From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D06C433E0 for ; Fri, 3 Jul 2020 10:51:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF6D0207DA for ; Fri, 3 Jul 2020 10:51:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF6D0207DA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 33E268D006B; Fri, 3 Jul 2020 06:51:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A0878D0066; Fri, 3 Jul 2020 06:51:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141BE8D006B; Fri, 3 Jul 2020 06:51:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id EF0018D0066 for ; Fri, 3 Jul 2020 06:51:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5236A1EF1 for ; Fri, 3 Jul 2020 10:51:03 +0000 (UTC) X-FDA: 76996447206.11.fight56_600791726e91 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 1620B180F8B81 for ; Fri, 3 Jul 2020 10:51:03 +0000 (UTC) X-HE-Tag: fight56_600791726e91 X-Filterd-Recvd-Size: 4160 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Jul 2020 10:51:02 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCF071045; Fri, 3 Jul 2020 03:51:01 -0700 (PDT) Received: from gaia (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DEB8F3F68F; Fri, 3 Jul 2020 03:50:59 -0700 (PDT) Date: Fri, 3 Jul 2020 11:50:49 +0100 From: Catalin Marinas To: Luis Machado Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, Will Deacon , Dave P Martin , Vincenzo Frascino , Szabolcs Nagy , Kevin Brodsky , Andrey Konovalov , Peter Collingbourne , Andrew Morton , Alan Hayward , Omair Javaid Subject: Re: [PATCH v5 19/25] arm64: mte: Add PTRACE_{PEEK,POKE}MTETAGS support Message-ID: <20200703104412.GB14950@gaia> References: <20200624175244.25837-1-catalin.marinas@arm.com> <20200624175244.25837-20-catalin.marinas@arm.com> <7fd536af-f9fa-aa10-a4c3-001e80dd7d7b@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7fd536af-f9fa-aa10-a4c3-001e80dd7d7b@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 1620B180F8B81 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Luis, On Thu, Jun 25, 2020 at 02:10:10PM -0300, Luis Machado wrote: > On 6/24/20 2:52 PM, Catalin Marinas wrote: > > +/* > > + * Access MTE tags in another process' address space as given in mm. Update > > + * the number of tags copied. Return 0 if any tags copied, error otherwise. > > + * Inspired by __access_remote_vm(). > > + */ > > +static int __access_remote_tags(struct task_struct *tsk, struct mm_struct *mm, > > + unsigned long addr, struct iovec *kiov, > > + unsigned int gup_flags) > > +{ > > + struct vm_area_struct *vma; > > + void __user *buf = kiov->iov_base; > > + size_t len = kiov->iov_len; > > + int ret; > > + int write = gup_flags & FOLL_WRITE; > > + > > + if (!access_ok(buf, len)) > > + return -EFAULT; > > + > > + if (mmap_read_lock_killable(mm)) > > + return -EIO; > > + > > + while (len) { > > + unsigned long tags, offset; > > + void *maddr; > > + struct page *page = NULL; > > + > > + ret = get_user_pages_remote(tsk, mm, addr, 1, gup_flags, > > + &page, &vma, NULL); > > + if (ret <= 0) > > + break; > > + > > + /* > > + * Only copy tags if the page has been mapped as PROT_MTE > > + * (PG_mte_tagged set). Otherwise the tags are not valid and > > + * not accessible to user. Moreover, an mprotect(PROT_MTE) > > + * would cause the existing tags to be cleared if the page > > + * was never mapped with PROT_MTE. > > + */ > > + if (!test_bit(PG_mte_tagged, &page->flags)) { > > + ret = -EOPNOTSUPP; > > + put_page(page); > > + break; > > + } [...] > My understanding is that both the PEEKMTETAGS and POKEMTETAGS can > potentially read/write less tags than requested, right? The iov_len field > will be updated accordingly. Yes. (I missed this part due to the mix of top/bottom-posting) > So the ptrace caller would need to loop and make sure all the tags were > read/written, right? Yes. As per the documentation patch, if the ptrace call returns 0, iov_len is updated to the number of tags copied. The caller can retry until it gets a negative return (error) or everything was copied. > I'm considering the situation where the kernel reads/writes 0 tags (when > requested to read/write 1 or more tags) an error we can't recover from. So > this may indicate a page without PROT_MTE or an invalid address. For this case, it should return -EOPNOTSUPP (see the documentation patch; and, of course, also test the syscall in case I got anything wrong). -- Catalin