Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3950219ybg; Fri, 25 Oct 2019 11:10:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwIjclidTj2AQVDGV9z+6g1x1XqYZl4IaPtvMOJBBB4M3IwZ972EG78HLz5fc/TwDZaioI X-Received: by 2002:a17:906:1e07:: with SMTP id g7mr4874653ejj.256.1572027016847; Fri, 25 Oct 2019 11:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572027016; cv=none; d=google.com; s=arc-20160816; b=daQvXuLrjFLtQkddgc3o9ipVad4Fs9ViJyGcBhBqn26lnn3r32KaGHRJrxqwe2wz5y D+Raj2L/ivsVwciYRdsazYBYMsra4PwEJOH4Qlx28/tTfBGzjED+3PVngsBKnYvWTWXn lDWekvFsmqksRxSlcuWLPnLUFaXXoRIrtsKxapc84uCGCN4UEui8sy1BShgrexbZ66lM sYkGE2yyUUrD2gI55fuI9Qdsqv7s2QdCHqtdUfRBNE+lMLe/rgMgT5BccZK4MBNXNhnd FlfEsfaWpt6yJEBnLueSr2GMkdk/C+o8SeIvL0NA5ikNr+zFIt04/D6Weqoami0qC5xq NA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5vJaRYj7Rplmta2jLUYto5zFdi29aZ0RMUS9kwrA3nc=; b=s+q3DV+qnl/ZbPyc07MAXmUj28qwAu3WIuUC57o1CnQ/6Lnmra0q+T7A7C3FD4DYAf ZWak8O9tGl3tNQ4hZR2G8qENZwsR1ZPL77e9FYOmCA+8m5emUSqPTP3nlNsb/0SsEC/w lm1ruRuSJRM0BBcXO0O0AmqrUL3fMd5l410fqrWmuTCjmHgnWvETgPbVuhLYSSMUPN8p giwLcsiKssYADpH+cdFeNGDW/8XhyHUSLN64vX9DmYiuFOET4Sqe5e568FZpaU2qMh+K D9XXtqaDX2n27fAHNz1+LqpRhMj2P4vYbLf0YtGZwpJuV+/i3bwytxXSN7P72qxuFoT1 6IPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UjxlRqau; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si1893839edf.232.2019.10.25.11.09.44; Fri, 25 Oct 2019 11:10:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UjxlRqau; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439738AbfJXQMI (ORCPT + 99 others); Thu, 24 Oct 2019 12:12:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:51464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439732AbfJXQMH (ORCPT ); Thu, 24 Oct 2019 12:12:07 -0400 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A5AA121A4C for ; Thu, 24 Oct 2019 16:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571933526; bh=BLLHDwROAf93/5MRoMht9A1lnkPiEcUf5wYfxbtqWxA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UjxlRqauqd1oPrLF6wvfCI5vlf/DbwgbzgAYwey/swEIg/Rfr34fBH2cSP+PmeuIf z6iEn1sirtCTIQESDvvm2jLkaitv4Ve6PXu2PtCzugch8oVQumox5H6z1aPgaku1aF Yz8Kopr2w9TnVbZTqYbnLd0ajio/aI2mxHDFKwWA= Received: by mail-wr1-f50.google.com with SMTP id o28so26728200wro.7 for ; Thu, 24 Oct 2019 09:12:06 -0700 (PDT) X-Gm-Message-State: APjAAAXERCkfbR4VNQKMo6bVwGxPSyuV9MN80QgoOsvos8at3NikUq9R pLmMMdR6Vjo3zyrdG1OScXTPlSH07Dn8PmrKJ+iv1g== X-Received: by 2002:a5d:4d0f:: with SMTP id z15mr4378059wrt.195.1571933525027; Thu, 24 Oct 2019 09:12:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Thu, 24 Oct 2019 09:11:53 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/stackframe/32: repair 32-bit Xen PV To: Jan Beulich , xen-devel , X86 ML , Peter Zijlstra Cc: Andy Lutomirski , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 7, 2019 at 3:41 AM Jan Beulich wrote: > > Once again RPL checks have been introduced which don't account for a > 32-bit kernel living in ring 1 when running in a PV Xen domain. The > case in FIXUP_FRAME has been preventing boot; adjust BUG_IF_WRONG_CR3 > as well just in case. I'm okay with the generated code, but IMO the macro is too indirect for something that's trivial. > > Fixes: 3c88c692c287 ("x86/stackframe/32: Provide consistent pt_regs") > Signed-off-by: Jan Beulich > > --- a/arch/x86/entry/entry_32.S > +++ b/arch/x86/entry/entry_32.S > @@ -48,6 +48,17 @@ > > #include "calling.h" > > +#ifndef CONFIG_XEN_PV > +# define USER_SEGMENT_RPL_MASK SEGMENT_RPL_MASK > +#else > +/* > + * When running paravirtualized on Xen the kernel runs in ring 1, and hence > + * simple mask based tests (i.e. ones not comparing against USER_RPL) have to > + * ignore bit 0. See also the C-level get_kernel_rpl(). > + */ How about: /* * When running on Xen PV, the actual %cs register in the kernel is 1, not 0. * If we need to distinguish between a %cs from kernel mode and a %cs from * user mode, we can do test $2 instead of test $3. */ #define USER_SEGMENT_RPL_MASK 2 but... > +# define USER_SEGMENT_RPL_MASK (SEGMENT_RPL_MASK & ~1) > +#endif > + > .section .entry.text, "ax" > > /* > @@ -172,7 +183,7 @@ > ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI > .if \no_user_check == 0 > /* coming from usermode? */ > - testl $SEGMENT_RPL_MASK, PT_CS(%esp) > + testl $USER_SEGMENT_RPL_MASK, PT_CS(%esp) Shouldn't PT_CS(%esp) be 0 if we came from the kernel? I'm guessing the actual bug is in whatever code put 1 in here in the first place. In other words, I'm having trouble understanding why there is any context in which some value would be 3 for user mode and 1 for kernel mode. Obviously if we're manually IRETing to kernel mode, we need to set CS to 1, but if we're filling in our own PT_CS, we should just write 0. The supposedly offending commit (""x86/stackframe/32: Provide consistent pt_regs") looks correct to me, so I suspect that the problem is elsewhere. Or is it intentional that Xen PV's asm (arch/x86/xen/whatever) sticks 1 into the CS field on the stack? Also, why are we supporting 32-bit Linux PV guests at all? Can we just delete this code instead?