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=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 B65ECC433E0 for ; Fri, 3 Jul 2020 10:52:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80D4720737 for ; Fri, 3 Jul 2020 10:52:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sDwGnE0Q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80D4720737 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Jw+ZYORl7V2rnatqF4zWqO7Vk31+Ibg15VugafyJ2mU=; b=sDwGnE0QBE04bRf/Hpziz3uB1 rVscWxrRfQ8146rdow6DA9srX1h6GgQaKmUAo/0EEHb2II6gu34HpYMeQFjQ3XVSR1MpebpIJItRC dA6hLSAEDp2ay87lEzIq6ULxJ/VinKGSuGF847Us+sloqEt8RarlHfJGzGninIHjfHTTCNKyNjEE6 gVou1CNxFBZmmN90nWYXRv5Kwn6qDkJ7aAu0K6tRvi4eOXdTHbdpucQtS7GkfEkHSJRfQsdAPfpQi 7Mc4h6WEAVQKAPDbgAIn1ib/BpJngD1TR1673NvklEj02sUHYI9/p+sJqebSEB5r9i5Ih7EOg/H8+ 0xIJmZpxA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jrJHd-0001FT-Uf; Fri, 03 Jul 2020 10:51:05 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jrJHa-0001Ea-99 for linux-arm-kernel@lists.infradead.org; Fri, 03 Jul 2020 10:51:03 +0000 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 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-Disposition: inline In-Reply-To: <7fd536af-f9fa-aa10-a4c3-001e80dd7d7b@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200703_065102_398079_DD1F3850 X-CRM114-Status: GOOD ( 21.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Omair Javaid , Szabolcs Nagy , Andrey Konovalov , Kevin Brodsky , Peter Collingbourne , linux-mm@kvack.org, Alan Hayward , Andrew Morton , Vincenzo Frascino , Will Deacon , Dave P Martin , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel