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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22A90C77B60 for ; Mon, 3 Apr 2023 10:17:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9904F6B0072; Mon, 3 Apr 2023 06:17:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 940E56B0074; Mon, 3 Apr 2023 06:17:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E18B6B0075; Mon, 3 Apr 2023 06:17:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F2B76B0072 for ; Mon, 3 Apr 2023 06:17:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2E7538087B for ; Mon, 3 Apr 2023 10:17:14 +0000 (UTC) X-FDA: 80639677188.01.17ABAFE Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by imf03.hostedemail.com (Postfix) with ESMTP id AB70C20019 for ; Mon, 3 Apr 2023 10:17:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm1 header.b="P WLLBsR"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=GCn6alqf; spf=pass (imf03.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.28 as permitted sender) smtp.mailfrom=kirill@shutemov.name; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680517030; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2X6kQY81kFbB9dD0hTeXUDO4hec/j/TMwLdo/emFpoY=; b=qVrFwNPRamuLdux3HxjmMb70tXfczhZ/3eD+eFs1EBV2S8WovvU2PdbE8KHuxrSPZSZAPv z48EQx/VtzWXEYWPaw+VvRTlYBItLAtTOI6+7/gQtvL9ZIR45wen9npiZPtxXTaXm51xOq /2PRtwfA4pFL50jszDccFwFEhSgAlz4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm1 header.b="P WLLBsR"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=GCn6alqf; spf=pass (imf03.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.28 as permitted sender) smtp.mailfrom=kirill@shutemov.name; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680517030; a=rsa-sha256; cv=none; b=iGbjF0aVHn9vVXyFFBZxDWuULcPdBLyl8kwrXh5kj1vz3MpjVsZD38q1XckfhWz7es7ZQP SPs5UfvXgoQLTB1FlL2xXDxqmvcuUSuRb5qvY4AEH9+z1Sw07naB0C0gEj6FGlT3vO5BLa HF3DpN/nNwBpPBmI2n/V5trH0MGhtP4= Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 0F9B05C0112; Mon, 3 Apr 2023 06:17:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 03 Apr 2023 06:17:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1680517030; x= 1680603430; bh=2X6kQY81kFbB9dD0hTeXUDO4hec/j/TMwLdo/emFpoY=; b=P WLLBsRKU3t6HU9mytrKeBmCsce7DZbXrEbUsP1XSyJocFnMliyjsW7SnrhRtB3kl +RJdXf/OUH3loUP8GtoUzEdn8h13+Z1I8baYYOlMCYxEkS4QPyOMLmxTj6LEGAnF 5YYGdEHZuvr5A3KK8ytIT4Boh+rVNJh9JPHPOClTSxeGPVe5uVCDLTajqhyPloGD nXy5uM8s0Fk/ZAJygBi2nOUhzQywjq4nxF8r+uCreRnXr6Rv4MInRqnRJiexhDc6 WRxWESBdAwFiwR1sTDoRBlQasm0pg8dyGb9dObhQOE5CB6lAS6lexRTnVKEw7FnS aPGS1IXrkrK8UuKUuNWKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1680517030; x=1680603430; bh=2X6kQY81kFbB9 dD0hTeXUDO4hec/j/TMwLdo/emFpoY=; b=GCn6alqfL8Z3dAUqoE+HVZPwtPvs+ xXfC3DT4YTTh2NGlc5tZn2Gh59F7uch966MlUSKIvMuv54SN5DF/vIawhnY6C4oa tBxWQmvyduZr9B/Co0hJNkSoxABDXJcvOKyr9koR+oanupXr0IgpOlgGDsY7Ggh/ HUbF9XwzXxj6hOiFqZJ/1s1fSzrXjwA5w1eub8WyR9aDet1wV3mCIhR4kMfaGYPF NYMjdxHBoK9A+mZ+QLLQUlOM0zUi69grpoEMrsVaDBn+qipctRjR9IgX5CdgwLuq Xq4n/k9r/vATx1HCCHwpR0ZLGY9lpFUNWAoDtomW9av+UOt5zPM1EZvNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeijedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepfdfmihhr ihhllhcutedrucfuhhhuthgvmhhovhdfuceokhhirhhilhhlsehshhhuthgvmhhovhdrnh grmhgvqeenucggtffrrghtthgvrhhnpeekvddvjeffheetgedtvdfgieejiedvgeejieet jeehieehveffueekfeehffdvveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehkihhrihhllhesshhhuhhtvghmohhvrdhnrghmvg X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Apr 2023 06:17:09 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id C0E9010D7B3; Mon, 3 Apr 2023 13:17:07 +0300 (+03) Date: Mon, 3 Apr 2023 13:17:07 +0300 From: "Kirill A. Shutemov" To: Dmitry Vyukov Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv16 11/17] x86/mm/iommu/sva: Make LAM and SVA mutually exclusive Message-ID: <20230403101707.satsniziz3tn2zyd@box> References: <20230312112612.31869-1-kirill.shutemov@linux.intel.com> <20230312112612.31869-12-kirill.shutemov@linux.intel.com> <20230403094419.zl2ncsd4qyd35fex@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: e1dimnd769ghsfer43xggmzorp9yu16r X-Rspam-User: X-Rspamd-Queue-Id: AB70C20019 X-Rspamd-Server: rspam06 X-HE-Tag: 1680517030-9610 X-HE-Meta: U2FsdGVkX1+O7QjO5nqH4Z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ADDCGtcCib9YpE1GE5HjK4gYs+4TdI2/LMw0BBbXCtlXSyN4XT76H6Sggw2gnOJFTRLiqzamlzR56wH4/s9Al18mGZFw6DxQ1DWZN150EsynEftX8tmQcudZ+duUYcNz6es1ncH07gIq+LXUk2LWkj3cr0jOB98dcsS27S0Vt9xRRl7z+nTgjyc0WIA7uP7y1zpNbDFxUi7qOQt5cWxmFX4ocDKl4HBoP4tOTjRCp+7+o 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: On Mon, Apr 03, 2023 at 11:56:48AM +0200, Dmitry Vyukov wrote: > On Mon, 3 Apr 2023 at 11:44, Kirill A. Shutemov wrote: > > > > On Mon, Apr 03, 2023 at 08:18:57AM +0200, Dmitry Vyukov wrote: > > > Hi Kirill, > > > > > > ARCH_ENABLE_TAGGED_ADDR checks that task->mm == current->mm, > > > shouldn't ARCH_FORCE_TAGGED_SVA check that as well? > > > > Do you a particular race in mind? I cannot think of anything right away. > > > > I guess we can add the check for consistency. But if there's a bug it is a > > different story. > > No, I don't have a particular race in mind. Was thinking solely about > consistency and if these things should be set for other processes > (relaxing the check is always possible in future, but adding new > restrictions is generally not possible). Okay. Makes sense. It is only reachable with task != current from ptrace, which is rather obscure path. Anyway, I will prepare a proper patch with this fixup: diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index eda826a956df..4ffd8e67d273 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -883,6 +883,8 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_ENABLE_TAGGED_ADDR: return prctl_enable_tagged_addr(task->mm, arg2); case ARCH_FORCE_TAGGED_SVA: + if (current != task) + return -EINVAL; set_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &task->mm->context.flags); return 0; case ARCH_GET_MAX_TAG_BITS: > > > Also it looks like currently to enable both LAM and SVA. > > > LAM enabling checks for SVA, but SVA doesn't and both are not mutually > > > exclusive. > > > > For LAM we check SVM with mm_valid_pasid() && !test_bit() in > > prctl_enable_tagged_addr(). > > > > For SVM we check for LAM with !mm_lam_cr3_mask() || test_bit() in > > arch_pgtable_dma_compat() which called from iommu_sva_alloc_pasid(). > > It seems that currently it's possible to both enable LAM and set SVA bit. > Then arch_pgtable_dma_compat() will return true, but LAM is enabled. Right. That's the point of the bit. It allows SVA and LAM to co-exist: The new ARCH_FORCE_TAGGED_SVA arch_prctl() overrides the limitation. By using the arch_prctl() userspace takes responsibility to never pass tagged address to the device. I'm confused. -- Kiryl Shutsemau / Kirill A. Shutemov