From patchwork Tue Jul 2 13:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13719649 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 1AE63C30658 for ; Tue, 2 Jul 2024 13:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D37F56B009A; Tue, 2 Jul 2024 09:21:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCCD86B009B; Tue, 2 Jul 2024 09:21:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEDD46B009C; Tue, 2 Jul 2024 09:21:51 -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 84D906B009A for ; Tue, 2 Jul 2024 09:21:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 46986A3EDD for ; Tue, 2 Jul 2024 13:21:51 +0000 (UTC) X-FDA: 82294875222.20.401AD91 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id 8563940012 for ; Tue, 2 Jul 2024 13:21:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ecvwrb8T; spf=pass (imf04.hostedemail.com: domain of 37P6DZgoKCDUpfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37P6DZgoKCDUpfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719926479; 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=ZE+7BbB3PE5kkYQMGtkK8hHnOxQPaKRTiUn2+3lo1Q4=; b=ChLdMLKtnL7ARIKIVAZ707WPeqqRFSHbVtbyWUy1thxAf405IHkhofJuLwVF09kSf/gqIx 0S56WhtNBoG29zZImWPA/BHg2TGbrfy9CBbY1ZwPrHrXnDPynLZpmfKru+XFEpPseOmeR9 sXZDIzWTOUVncNrTDDT/egvoLrQVJb0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ecvwrb8T; spf=pass (imf04.hostedemail.com: domain of 37P6DZgoKCDUpfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37P6DZgoKCDUpfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719926479; a=rsa-sha256; cv=none; b=lItn0xlqjmtCmveQdWHIDIS4nYDMo/cTx5cJN9viBjIUABCxoJlvww9L1r9P3pCmgj4oTC 9om4GoBEbfOHRxP5G2tbhrrII1VI/TXHqGy2CvowWEmCbcFjJ9KtYa3qBsnHuMETldqh3+ +x3ySfnJ2lWu3AUxD+Lx4MVleEmM8/A= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03641334e0so5885595276.3 for ; Tue, 02 Jul 2024 06:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719926508; x=1720531308; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZE+7BbB3PE5kkYQMGtkK8hHnOxQPaKRTiUn2+3lo1Q4=; b=ecvwrb8TNo1/UZgd0BwVExc1b8Djhehq3jytKBsFs1m1jwAFteNHgqQgw2qkq9UrGj 4YLTNVkj4FAso4xJIYlT1n9+dcmBUQLXb9IKz1HY4drtXefJulKIySOJDHfWJgjISpAe qeDWU1OD+RCkJk/+FslKP9mp02AihUu1/2wWnRldLngln4+Xze6xEHO39HzlwrAiX0Qu 6skY7Vqaxo/75nYkJzEblWJ5qh2hPCB6eEfS+nJumioLSVANCDvAc+EsF62NH774D5/+ LnSeKcODaxcCHyrDesY++ac50qhCEcJUfay10XTuQCWd/EGtjGI1jkfYvzx6qjoyPR1m 6JZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719926508; x=1720531308; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZE+7BbB3PE5kkYQMGtkK8hHnOxQPaKRTiUn2+3lo1Q4=; b=uTmVgedAZhwcz7KgKzJnF+cS8Li13RM988tyMoPrA+GrcLckRLXv60RBC4Ol2HnYsW NZL9vb2wPSwabuGxqgP7nSdYzT2AXBqw+2T4CCSPAZ6AepfEZ/x/ZiOSaQjmsQUxm412 bFmKmTr9wHUzEln/L6Pg12jBJmgeiNVmHy/6TaEtpRxf024jju4QDppNrdLICDiJgtaB hqa2x7tpFachugGNF0i6+OB7Fa+2Ctlz9FQXABigUy4l+LFwyyDnOQNayS7UKGOjU8np ljEjxEyzx0i0rCQna4cjc4TUfO5gklrhdU3j7HNE5tsveeTD9Clpibolf/MGN7w84+ob 8E8A== X-Forwarded-Encrypted: i=1; AJvYcCW6k5Ar6bcSJ+qc8RKoHi9/MY8BRhpZHgsL8CqV5Ng9EAjlwydqLmehoLKTNr8eLAUNXtBVlIope0xHxu+X8YOWm2w= X-Gm-Message-State: AOJu0YzxPX3S00AMg3kdS9aLGwdPr6iUwePfuqnw73xETZvSaR6VR1cx Wmw0YUk24gKYbnYfouoBhRzCQNXSyWPX1rQJsTWW9YSEGACb3VP8DdTCpxaRDCv4Vu8rZBk0DoU d66i9Kc+uLbXrOLFW1g== X-Google-Smtp-Source: AGHT+IEqYo+qKpL7nHdD6wl5aRfdtl10keDX5LkNKDvlJA032DzVMnyh1cjIdyzuauJzkL055yfoCx7EJnhJcG3G X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:10c2:b0:e03:a5a5:3204 with SMTP id 3f1490d57ef6-e03a5a534e7mr542276.6.1719926508503; Tue, 02 Jul 2024 06:21:48 -0700 (PDT) Date: Tue, 2 Jul 2024 13:21:39 +0000 In-Reply-To: <20240702132139.3332013-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240702132139.3332013-1-yosryahmed@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702132139.3332013-4-yosryahmed@google.com> Subject: [RESEND PATCH v3 3/3] x86/mm: Cleanup prctl_enable_tagged_addr() nr_bits error checking From: Yosry Ahmed To: x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Kirill A. Shutemov" , Rick Edgecombe , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8563940012 X-Stat-Signature: 5ge3skog7jg6hyxk7trjthy41gc1nmxj X-Rspam-User: X-HE-Tag: 1719926509-114021 X-HE-Meta: U2FsdGVkX1+9yMkpQ5ZIH1EY8acdygCQqX5N1Ht4XhJpeewEev9kQ4VmKj9rtuLO+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b1C4Ed7tHEnTm1Co2QiRmAawlGLCTfstVwYC6DX8As5fxjFXaLy1UENb6ANl4MjXIpfYEmLpv+omwap9jy/ZXulVRI7fZTCvLdygvzFNGfdN9CIhGG7eA6jD6D3fCZzTiz0sM6Rblc2bbLB3aJeG+/p5ZP9QH9WJYdB7FNV/g5tVIDcTmMwvcXMLtXhrROJ9Z5RyhCi0xXBuIGDq5PGbVjGsMAImmHmvmoO4HTgDm9GPn2hWGgoTLjp9nDcUHzPGriIKCPby9JcPbB8Txh39LuDXWIgKBvv9cwTLhQeHOSlmrQg14iSPAWjfOJX2Brz+xhcypkLteoQVbAXKbJPS8GMULwSAyl8UM6+MccwO6HKXm3098u6iDX89QOLW8tcpxL8FjcZOxfQk/sTX6EmCw64POGLvQipl3gfb4TaCdie/sj2J5c/yuZItu860qOsVCcBha/zRVbtpAw== 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: List-Subscribe: List-Unsubscribe: There are two separate checks in prctl_enable_tagged_addr() that nr_bits is in the correct range. The checks are arranged such the correct case is sandwiched between both error cases, which do exactly the same thing. Simplify the if condition and pull the correct case outside with the rest of the success code path. Reviewed-by: Kirill A. Shutemov Change-Id: Ia4f78de99d02f8ce28787346404d59ef13ca3d92 Signed-off-by: Yosry Ahmed --- arch/x86/kernel/process_64.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 26a853328f2d4..c62098332f05c 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -831,17 +831,13 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) return -EBUSY; } - if (!nr_bits) { - mmap_write_unlock(mm); - return -EINVAL; - } else if (nr_bits <= LAM_U57_BITS) { - mm->context.lam_cr3_mask = X86_CR3_LAM_U57; - mm->context.untag_mask = ~GENMASK(62, 57); - } else { + if (!nr_bits || nr_bits > LAM_U57_BITS) { mmap_write_unlock(mm); return -EINVAL; } + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; + mm->context.untag_mask = ~GENMASK(62, 57); on_each_cpu_mask(mm_cpumask(mm), enable_lam_func, mm, true); set_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags);