From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117561 invoked by alias); 8 May 2017 09:18:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 117547 invoked by uid 89); 8 May 2017 09:18:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=taste X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 May 2017 09:18:50 +0000 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v489ImH1130358 for ; Mon, 8 May 2017 05:18:51 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aakg48c02-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 08 May 2017 05:18:51 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 May 2017 10:18:43 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 8 May 2017 10:18:40 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v489IddS11272450; Mon, 8 May 2017 09:18:39 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E43EEA4040; Mon, 8 May 2017 10:17:21 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B00A7A405B; Mon, 8 May 2017 10:17:21 +0100 (BST) Received: from ThinkPad (unknown [9.152.212.148]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 8 May 2017 10:17:21 +0100 (BST) Date: Mon, 08 May 2017 09:18:00 -0000 From: Philipp Rudo To: Yao Qi Cc: gdb-patches@sourceware.org, Yao Qi , Peter Griffin , Omair Javaid , Andreas Arnez Subject: Re: [RFC v3 4/8] Add kernel module support for linux-kernel target In-Reply-To: <86d1bnouo0.fsf@gmail.com> References: <20170316165739.88524-1-prudo@linux.vnet.ibm.com> <20170316165739.88524-5-prudo@linux.vnet.ibm.com> <868tmf8kn4.fsf@gmail.com> <20170503181620.53d0bd3f@ThinkPad> <86d1bnouo0.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17050809-0012-0000-0000-0000052456D9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050809-0013-0000-0000-0000185EB993 Message-Id: <20170508111837.2bf0bda8@ThinkPad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-08_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705080054 X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00181.txt.bz2 Hi On Fri, 05 May 2017 22:33:51 +0100 Yao Qi wrote: > Philipp Rudo writes: > > >> > +/* Translate a kernel virtual address ADDR to a physical address. */ > >> > + > >> > +CORE_ADDR > >> > +lk_kvtop (CORE_ADDR addr) > >> > >> How about lk_kernel_vir_to_phy_addr? > > > > I prefer kvtop. It's much shorter and (for my taste) is just as readable. > > But I don't insist on keeping the name. Are there other opinions? > > > > or maybe lk_vir_to_phy? What about lk_virt_to_phys and lk_kvirt_to_phys? For the general virtual to physical translation and the special case when the kernel page tables are used. > > >> > >> > +{ > >> > + CORE_ADDR pgd = lk_read_addr (LK_ADDR (init_mm) > >> > + + LK_OFFSET (mm_struct, pgd)); > >> > + return LK_HOOK->vtop (pgd, addr); > >> > +} > >> > + > >> > +/* Restore current_target to TARGET. */ > >> > +static void > >> > +restore_current_target (void *target) > >> > +{ > >> > + current_target.beneath = (struct target_ops *) target; > >> > +} > >> > + > >> > +/* Function for targets to_xfer_partial hook. */ > >> > + > >> > +enum target_xfer_status > >> > +lk_xfer_partial (struct target_ops *ops, enum target_object object, > >> > + const char *annex, gdb_byte *readbuf, > >> > + const gdb_byte *writebuf, ULONGEST offset, ULONGEST > >> > len, > >> > + ULONGEST *xfered_len) > >> > +{ > >> > + enum target_xfer_status ret_val; > >> > + struct cleanup *old_chain = make_cleanup (restore_current_target, > >> > ops); > >> > >> Use make_scoped_restore instead of make_cleanup? > > > > Using a scoped_restore probably makes sense. Although I don't see the > > advantage over old style cleanups other than having marginally shorter > > code ... > > We want to reduce the usages of cleanup, and even completely remove it > ultimately, so we should avoid using it in new code. Yes, I understand. It's just that you replace one mechanism to restore the global variables with an other instead of removing the root cause, global variables... > >> > + > >> > + current_target.beneath = ops->beneath; > >> > + > >> > >> Any reasons you switch current_target.beneath temporarily? > > > > Yes. lk_kvtop (at least for s390) reads memory if the address is not > > physical. Thus reading a virtual address calls xfer_partial twice. Once > > for the actual address and a second time for the data lk_kvtop needs. This > > can lead to an endless recursion if there is a bug or memory corruption. > > Switching to the target beneath prevents this. > > > > Does it work if you pass ops->beneath to lk_kvtop and all lk_read_XXX > apis, so that we can use ops->beneath there instead of current_target. Well switching the target is 'just' a backup. Only a few lines below in lk_xfer_partial I do this ret_val = ops->beneath->to_xfer_partial (ops->beneath, object, annex, readbuf, writebuf, offset, len, xfered_len); Switching the target assures that, if ops->beneath->to_xfer_partial calls other target methods via the global current_target those methods also belong to ops->beneath. Moving this to lk_kvtop or lk_read_* wouldn't prevent the problem but would lead to code duplication. Thanks Philipp