Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp825238lql; Mon, 11 Mar 2024 21:00:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8aN0Hg/e3FlPK/f0VC3QH2J9S/nhnKVo9ibTqpB+b2/dPisBz8BYJS3QO1eGulXHOXNbreguuo16jpokWat2NHB0kZmrUHisAw6+k5w== X-Google-Smtp-Source: AGHT+IEPM6ppCohjEvXyCnDr0ABdtW2HaWg+tHl+y6VtSwEH7b2IjPzHXoI40FCxhcK1YFtiV59k X-Received: by 2002:a0c:fec7:0:b0:690:da82:5633 with SMTP id z7-20020a0cfec7000000b00690da825633mr3222123qvs.19.1710216024364; Mon, 11 Mar 2024 21:00:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710216024; cv=pass; d=google.com; s=arc-20160816; b=D6eSOum34aBDlB17SZDcKkkDwJR3RcMoUDQWKbCsOCBshtNop1KYnoeiTo1jPehYT8 Blxjy0NG1/GL7b+EM2OS3kKfs24xrFtOa49xVER/QKDh+HxHq9Z7jfC2hhr1xk/PyiBx 6GyD6T1jv0iUIJgXKAFpe55lxxN52fOHxkg5wuTEwZ/IEVplFpLfWGNH8RSK6TKZOZbI 20cf3Pp3gkWQQDEWhgCHbKSaHq0QWbGixq7niYBXxWcGQD0lQR/c+MIXYS/i4sxxysWP REnzBo3ndjyv8Z+pc/i3GzsGCwxPwDIlyH0vBSR8+7/Pq00+KwkV2AdaABD7187/Umb2 3xYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=UAJ+3ue8h2GtGeMmVF7aptze9cHfLRbMGaK/pSc8DQk=; fh=Z5UXTawNgJlvNhVJflyu8wFpSIUGmRFkGJ0YPAZC9M8=; b=kVu5TtOQ/ONZJYE8o9Ax02mUaTCz8yfC6hwAVaW7hwKjCkhkii4V5h2QhP+WV3f9x1 f2TayCE4v2tgGmPjf+C/QJdonxRxWzUrHBc/8lu6Tttc8pvx5BKvAJv+Fu9o0s8uiWZ3 ZtbfzI8JgmowqrmZI2fEgeWFkfkU8ee+ZI8ihYyQkb72skTjeFoCVXzEdiX0x+u7HtqZ pbD3XH7GjsBeavVkFBQeKOjMEttG6BVvlCXmKMLsedjxVvSoKYMmDzmQGA91aweT5Pen Fc+bsxarHb44gsnq/0ivGd1o5oisvQl/qO0Xg3nvyhxGqRc4eN7dTH/LpeptTBsLat+V 9WAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ueph0Upu; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-99808-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99808-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g15-20020a0562140acf00b00690182dfff3si6760654qvi.216.2024.03.11.21.00.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 21:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99808-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ueph0Upu; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-99808-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99808-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1BE891C21703 for ; Tue, 12 Mar 2024 04:00:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9257717590; Tue, 12 Mar 2024 04:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ueph0Upu" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38FADBA39 for ; Tue, 12 Mar 2024 03:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710215999; cv=none; b=kHjU/stPT3JZuBNbXCVhjcduW7QCKiZfqhljwUC1EOl1A1NY9pgACjXJERlHWyzUGl2ClNs7J4wXKYIugA3AdFFvrp21fXC96o4c5/n3o5fjp5GjMKAfKpeyzX1z3wNMl23OJr8W8GD/IAaoWfRAOfjPs2yG66V8Z0ZBEuG0KQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710215999; c=relaxed/simple; bh=ii5uJKIR1GUQaXN/wXyriaRdctB7IViTNGsZQo615/c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=J8sSntCS+gtFuT6B3I/zPViuMVvcAvgOa9/C6uwsZDYzv+O2AgncDfsWk0xhbbJdJK+dVrUq4ditG/PQKgcj2SQxOaQWDo8kJjnfsdO52KOMAE+iyK3NymyLVVMvNQFdvd2rlKLY2Dz2Ddc3Fr0RoOqwm6B9/7FcVgw5XZvJUN4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ueph0Upu; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso10008187276.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=vger.kernel.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=Ueph0Upu0fPJpwsOU9xMB6/rfyQTv8vvQSQQmteEjjm1T0c/q73aDg1ODnRG4bpz8u IDfQljVtnlj4NnpUzVeUVFiTzx1qAUoif8InLJj2tOpYM1yQnLDXiO2bjp7f2fJUd0iE H6Hy0VbC57cnCmW6vFdS70Y9QxC0ZbwlSW4XFtSJ9uh3il7XwTFDfceBynGZJmuPF0JW o1+hwbYM2LEDImZ+3bj8m3hovP0Kf8S5teuKDR7vj706MLhu33UIctcf7tMLRclxVg5/ mbp6ex3Q6LEJViwyWX7j3ORr01znmGmEcb9vkahTGZiBGo5mqfWBWG7VAVzOm+jICzXn /v0A== 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=eS5OHFLjY79PteTjywraJN1lAbXPYfR07iYgAnYGTo2KrNWRrnGOHXM8wWKikBh4Gh e82KoARoH4auW75KXgYbW8hQBwvVOXi/cz0xGL1k9heV9ZIgez/LDb0fWIC7ePeluk3C qu8QbanYV9QAXtl3EiLzsrwzUDnkYY7FjecBZF688NJBuiiHULeiOYziG3t61d/GRYcy oYAEztxNqjzWxMqd8ck4T4FQWiMBR3ExVPCoxI16y4HpMk+sod3ZdTYoCFTEoIlE6Ag+ CCmT0HhN5SYvR/FvvciBnO3etvAhwPP4IZWFlvnWH1a7yIW8CmH2Px+gLnEOF07nnYtF qQxg== X-Forwarded-Encrypted: i=1; AJvYcCVEbw7DIHL9bNMTFUxyHBQV7cFE2PfvLlDbh73e86zOI499wFFGjg6k2Cc9+5U7mGKVJ21KO8abvgOd+NkmS6axVjdSc7ftBwiIrD49 X-Gm-Message-State: AOJu0YyZnYsiAkt8Ia5j0ir8X7aKbqCbGY9RIbuBqB8lreJO7c7Aeel6 pr+m7VOImUgG4MQDscO7F0tqNMcvY4yLB9hoTPfcPru6RHX/IITIKS/vQi2HDDCxQSyp4pB/GpE FGdHJp58aIYH8Zs8nyg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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); -- 2.44.0.278.ge034bb2e1d-goog