From patchwork Tue Mar 12 03:59:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13589507 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 533CCC54E49 for ; Tue, 12 Mar 2024 04:00:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6983E6B0181; Tue, 12 Mar 2024 00:00:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6464F6B0182; Tue, 12 Mar 2024 00:00:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EE956B0183; Tue, 12 Mar 2024 00:00:00 -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 3BC0E6B0181 for ; Tue, 12 Mar 2024 00:00:00 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D21FB1C106A for ; Tue, 12 Mar 2024 03:59:59 +0000 (UTC) X-FDA: 81887033718.30.1AA5E07 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 2F6DA1A000C for ; Tue, 12 Mar 2024 03:59:58 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gdtrCXj+; spf=pass (imf19.hostedemail.com: domain of 3PdPvZQoKCNgSIMLS4BG87AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3PdPvZQoKCNgSIMLS4BG87AIIAF8.6IGFCHOR-GGEP46E.ILA@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=1710215998; 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=UAJ+3ue8h2GtGeMmVF7aptze9cHfLRbMGaK/pSc8DQk=; b=cVnqsMVtejCoNic03zYi9undY3Fh2lkEfPxVplhemw/eQldARygK5yTn82hDSAf/JhTI0z 04w1cXXJByIfHmU8mtn9Zeh1mXrhzcM/AMs+1xfwC1zX9v+AaeJGGOkFqgGIxdWMjpdgOL fx2k+00MWX7OTTwryI45car7dkmC0CE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gdtrCXj+; spf=pass (imf19.hostedemail.com: domain of 3PdPvZQoKCNgSIMLS4BG87AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3PdPvZQoKCNgSIMLS4BG87AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710215998; a=rsa-sha256; cv=none; b=qv44Ke+cQGF+E17XgdLfSkOxELKHtDlULHtmI7EBaSfvMmt0yvACac2GhYjQPHDYagzVyB 3wvKXKjPtotIzc1LFli0wdI/awpvaATMWurNikDnum6uVLoBh95muTWT2h+325adV/ySuB LdT68uq7hLRXg/L/ndaTIAqvY0ZD2bA= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso10008189276.0 for ; Mon, 11 Mar 2024 20:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710215997; x=1710820797; 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=UAJ+3ue8h2GtGeMmVF7aptze9cHfLRbMGaK/pSc8DQk=; b=gdtrCXj+CKpi8jNlRjTE3mTpschFMKGslZpRqkTT9OK1eRCS7+GyINDLhCa6nE0XoX EogvG/wGcOkJDTgUftQGsXaqQBdk/qaMJy1agu2Dm8+1/NCdHkn1uImQN0iT80Dus4qA SeZMKUGjkyAYjjxuyuGYx29UYB2I+me8YwZCHQOVg46z9YSB/woV6umxsX3fHuHaiCg7 z+SbzJ7csQP6kMIoklULWn0vF9idLy1dt/V/b9TjKTCgeCUwV5fGQiHOCmr0fgwG5+sV qRoVj/HtbUYzzYlLG/p0w5HF1nhW140sy7IJm0M+W8mFYmUqHOxUOmyPnVZT5vXuHXUG +L9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710215997; x=1710820797; 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=UAJ+3ue8h2GtGeMmVF7aptze9cHfLRbMGaK/pSc8DQk=; b=LJgycmPsSg+l1x0CKcl1I7ZatNwSqZ22JTDeRLoyJ6XZMKnnTUmAwsPLh2qJQCmCNu 5EHfUW57Cjl+NPne5pUo2WEriiAsc5SXX0KKp9OBTjNf7VEX13zpF7vfoy+xhjX7+kDr QwK+5iUWfevk5oO+23n5p7eQkl8nTZCxqNVi3+hNRrLjAtaJg9/gXZA7SSkGs5USK/El yv8aiUgTvr2lolinRLXtS22zymTRlVWmV/MA1e+ba24F/g5iUUw4qtGE7OGZuphog/Yh q/imIlMVlJcSJrtE+xVSt76c4Pr7RUq+YZjPK6sznnHoi/22OHWZtLmvXUgv2sMDyJUh qlDQ== X-Forwarded-Encrypted: i=1; AJvYcCVvlteFcmfs1rR3gqtiL7RtlARCW1wVN5UCu+RcAhw7etZ3EKml5c+nVPv44MzcynZuUn9g9pCH50o849dy3WmXcco= X-Gm-Message-State: AOJu0YyNANzPjPU5ZELQ8eaWzWyRrUAD0zSChBTKL1KDG2wVWnxGLrtk cZe0omhThWAJEroJptpcKGqyixlkj+dDg5FAej9M3rqYdXbG320K2EDceBxC2UKIZHAGIY7Erce rw4O1weoJ79B5ynQq/A== X-Google-Smtp-Source: AGHT+IHHHQjD/GEWT164UF9qNBAO6Zdv0oaS7UwIqMuvXE4Wlv6Tn55WWEmKnE3lYPTXnbsqaib7icEdWoIEAoBS X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:98c5:0:b0:dc6:e884:2342 with SMTP id m5-20020a2598c5000000b00dc6e8842342mr2710694ybo.5.1710215997281; Mon, 11 Mar 2024 20:59:57 -0700 (PDT) Date: Tue, 12 Mar 2024 03:59:51 +0000 In-Reply-To: <20240312035951.3535980-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240312035951.3535980-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240312035951.3535980-3-yosryahmed@google.com> Subject: [PATCH 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-Queue-Id: 2F6DA1A000C X-Rspam-User: X-Stat-Signature: tuxway7uauqni68agnu3b989ea5a11kj X-Rspamd-Server: rspam01 X-HE-Tag: 1710215998-262722 X-HE-Meta: U2FsdGVkX18w87EE23m7vn3lIQRy81Loa34KUq1Kkz2nR/JsodBM3JqtG48+C2C5JC0tGzKTo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uyrLAbQop8tnlvFhcypLbDKyM7pv5dT+9l3RBjxbMiUfYqZeQWayeZhY5g0vCntY08yeQM2RAK3M7IadtUPjVH4bj5CahG3QIIE/uO0si5XB+jrfFNHtN6aTjlkyA9gP2Lyz3TGGwVD4Afjwmk4XcA+87Q7bjbgEFj0Ec/bEqKX6NRGcROna5k6scxcc+DBGn1eQ9Ut80RZtIa8XYw+eyQoSyt91va495AdGRE79zzMIyYflJv6rIi3THKXV3LbW6FF3dtwQ= 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. Signed-off-by: Yosry Ahmed Reviewed-by: Kirill A. Shutemov --- 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 748d2b3bdb985..0608c4df4e95d 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -783,17 +783,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);