From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 6BFA22BDC2C for ; Wed, 21 Jan 2026 11:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768996157; cv=none; b=C8hehX8UsNlBBQl5GyTjpr5xMGdC5FQYApipeX5yNGIpjiOLm51ZyRGeYwMsYfrMw4zhtj1ILdtanS+Bd6O12Mslmod0cVqE3wwQpkQMRz1PC1QIKPsfAtTVOFvw5UX6QJD4a+0thp59OrDUB58POPa62+tqBypexbX2rW+QjD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768996157; c=relaxed/simple; bh=9P1oxkkeGLl+73G/RPeJ2iahSpfwZQV1OvoeFEU4suU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PAE3BKMT4CYYgmuNfYsuh6hXGUXGbGErfclKcDuThBCcgNvx5uBi/yYX5T/ATn9etEoe8CB/WcDjW1MRFrHukuZn8989almWiqOUSfP2cnDVXl1ZAnT1Z2mJGAj685yg++faOsD1UKWOaon6G0rFJb8J7lWKpG0jqeHTKMvLpL8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mLl/f9Mh; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLl/f9Mh" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-47ee3a63300so62059005e9.2 for ; Wed, 21 Jan 2026 03:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768996153; x=1769600953; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ITBIXZk62NEbtB+Nq7VhAQKuPqht3R7UkgTIbCgdcCA=; b=mLl/f9MhdM9HRx0j86732c8tFXgpTPg8pyuLqSFext1SHcjNG6VbPL+9Dq16HGPR4C cutAf7N1glY1/g7DIOHsB2BHL1uyuC2J92weLVBQN+Wgh6SNY0OShWrWowkKSZByBwye t3d2FAtzwVRvaNui2XJalkP8c9guiHX4OlnUXZm4NcMzJi8Ncho8xbHq0Z4FYmyu/9Rt d9uWzBkL73a1uiqG7C1t1je24jH/xeUOpiy74bZWtz57cj2YjfJvdvMkPynNJ+aAWUsh I39Hkxz2zNNsKbx/St35KOk4yIxQCsIfren9z5mG1ZCN3py37hyoy5ZxkIU/NqgACQVz ssiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768996153; x=1769600953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ITBIXZk62NEbtB+Nq7VhAQKuPqht3R7UkgTIbCgdcCA=; b=vz3Lo7kMOlkcdEVM0JmJiDETgBe51aexzIGzg14riDA2N5CTUPWHmGWCULA2dD235S eqZNNhaJ0hTcuH2uLGF9+4yPiLGsuUIsM7zhDK5FJp/RmkkCITN7Oo0B3gxbdZGXwv1O TNZvDKDUEp+7TUZ6SNGQLlCftQ200eQqOZJcbaAdrsjH6zv47lSriGBjmM3LiMLAAyDD 7YfEKoGQAyY0J1LxJCDk3nmJ5K8Aq49OdsLhAXtfX0kDZ8QuOtfwiR7+z/KJPKCr2p02 npyX3qVtMR6hm/5ms8AW9UF1BE5YxVFiq0jsS4lwEXOdymxYmsGB6siku3GjfNDUAkr5 eBTg== X-Forwarded-Encrypted: i=1; AJvYcCVYW6hRG7gBrZdL3Yf53IjMVt011Gfpp+pJmKVmyNkrpJ1u4nhLn3gALP8m8OSXhpmYgTcZZBrYA8dnpYo=@vger.kernel.org X-Gm-Message-State: AOJu0YzAJ0PWLDIFcHKGnosRVrZWhaNg5z1IHQX1cjH2XgGhgZFVKCQ9 RDo3ZJSNhZSUqKuHRg9TLGmio1pOocIUgDPZhrMjUH7tAo7lMviJoItB X-Gm-Gg: AZuq6aL7o8YYz5f+mvStGSlUquEdB4fyAElkSfyDv69inxg6WywMo26+CPrdrl1gubS 2zKYniF37lFqS6XCOIZ+QJsJ2we3RqYDnRk0eSmzKuhR22JZUebO5AIVY5Pr5FDwLLhTi/Sg3E9 mVr888qO1m5DUZzhJaISTPlWnibBgYmyS22A9QGqQSaQ9RL3l6WIU5z7DLJyC606/EO48Ykspg3 /3Z+tW3i3Alii8PKFa0dZyaoCR+qLXXUjJ3Nz5xZXJ0hI2LCk2L/U27QwpQ3ml3mrUGsKcpmNs3 PP6hUgGsgIT18+CITkWWN91dOUCyXdWJd7u+Gwqc+OfGNQjDc/t0m19LpigT5fMVjBmnIH0u9jI ep1Q32CBH4m2ulDhWhJQuH5VEucJnIhxTfeJO9VYBqjw420Wetr/qXX9t/8p8Cabeig5nWv6lkR zH6emWZpp2M2ZU/dBmQRqKUoSoe/fYY6BrFsvOZ1fpbNfkDhrasKKS X-Received: by 2002:a05:600c:4fcb:b0:477:7bca:8b34 with SMTP id 5b1f17b1804b1-4803e78fdb4mr79504775e9.6.1768996153461; Wed, 21 Jan 2026 03:49:13 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47f429071besm357824995e9.10.2026.01.21.03.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jan 2026 03:49:13 -0800 (PST) Date: Wed, 21 Jan 2026 11:49:11 +0000 From: David Laight To: "H. Peter Anvin" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Uros Bizjak , Petr Mladek , Andrew Morton , Kees Cook , "Peter Zijlstra (Intel)" , Nathan Chancellor , Kiryl Shutsemau , Rick Edgecombe , linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, x86@kernel.org Subject: Re: [PATCH v1 12/14] x86/boot: tweak a20.c for better code generation Message-ID: <20260121114911.6adc2838@pumpkin> In-Reply-To: <20260120195407.1163051-13-hpa@zytor.com> References: <20260119192923.651588-1-hpa@zytor.com> <20260120195407.1163051-1-hpa@zytor.com> <20260120195407.1163051-13-hpa@zytor.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 20 Jan 2026 11:54:04 -0800 "H. Peter Anvin" wrote: > Do some minor tweaks to arch/x86/boot/a20.c for better code > generation, made possible by the __seg_fs/__seg_gs changes. > > Move the die() call to a20.c itself; there is no reason to push an > error code upwards just to die() there. Can't this code just do: sv = *0000:addr; val = *ffff:addr+10; if (sv != val) return 1; *0000:addr = ~val; io_delay(); val ^= *ffff:addr+10; *0000:addr = sv; return val != ~0; That inverts all bits, inverting one is enough. No loops needed. David > > Signed-off-by: H. Peter Anvin (Intel) > --- > arch/x86/boot/a20.c | 24 +++++++++++------------- > arch/x86/boot/boot.h | 2 +- > arch/x86/boot/pm.c | 3 +-- > 3 files changed, 13 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/boot/a20.c b/arch/x86/boot/a20.c > index 52c3fccdcb70..38a1cad8a553 100644 > --- a/arch/x86/boot/a20.c > +++ b/arch/x86/boot/a20.c > @@ -53,24 +53,22 @@ static int empty_8042(void) > > static int a20_test(int loops) > { > - int ok = 0; > int saved, ctr; > > set_fs(0xffff); > > saved = ctr = rdgs32(A20_TEST_ADDR); > > - while (loops--) { > + do { > wrgs32(++ctr, A20_TEST_ADDR); > io_delay(); /* Serialize and make delay constant */ > barrier(); /* Compiler won't know about fs/gs overlap */ > - ok = rdfs32(A20_TEST_ADDR+0x10) ^ ctr; > - if (ok) > + if (rdfs32(A20_TEST_ADDR+0x10) != ctr) > break; > - } > + } while (--loops); > > wrgs32(saved, A20_TEST_ADDR); > - return ok; > + return loops; > } > > /* Quick test to see if A20 is already enabled */ > @@ -125,7 +123,7 @@ static void enable_a20_fast(void) > > #define A20_ENABLE_LOOPS 255 /* Number of times to try */ > > -int enable_a20(void) > +void enable_a20(void) > { > int loops = A20_ENABLE_LOOPS; > int kbc_err; > @@ -134,30 +132,30 @@ int enable_a20(void) > /* First, check to see if A20 is already enabled > (legacy free, etc.) */ > if (a20_test_short()) > - return 0; > + return; > > /* Next, try the BIOS (INT 0x15, AX=0x2401) */ > enable_a20_bios(); > if (a20_test_short()) > - return 0; > + return; > > /* Try enabling A20 through the keyboard controller */ > kbc_err = empty_8042(); > > if (a20_test_short()) > - return 0; /* BIOS worked, but with delayed reaction */ > + return; /* BIOS worked, but with delayed reaction */ > > if (!kbc_err) { > enable_a20_kbc(); > if (a20_test_long()) > - return 0; > + return; > } > > /* Finally, try enabling the "fast A20 gate" */ > enable_a20_fast(); > if (a20_test_long()) > - return 0; > + return; > } > > - return -1; > + die("A20 gate not responding, unable to boot...\n"); > } > diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h > index 4d3549ed7987..584c89d0738b 100644 > --- a/arch/x86/boot/boot.h > +++ b/arch/x86/boot/boot.h > @@ -167,7 +167,7 @@ void copy_to_fs(addr_t dst, void *src, size_t len); > void *copy_from_fs(void *dst, addr_t src, size_t len); > > /* a20.c */ > -int enable_a20(void); > +void enable_a20(void); > > /* apm.c */ > int query_apm_bios(void); > diff --git a/arch/x86/boot/pm.c b/arch/x86/boot/pm.c > index 3be89ba4b1b3..e39689ed65ea 100644 > --- a/arch/x86/boot/pm.c > +++ b/arch/x86/boot/pm.c > @@ -106,8 +106,7 @@ void go_to_protected_mode(void) > realmode_switch_hook(); > > /* Enable the A20 gate */ > - if (enable_a20()) > - die("A20 gate not responding, unable to boot...\n"); > + enable_a20(); > > /* Reset coprocessor (IGNNE#) */ > reset_coprocessor();