Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1302076ybx; Thu, 7 Nov 2019 10:04:59 -0800 (PST) X-Google-Smtp-Source: APXvYqyoHArVquLW2bZERdQVkyLmjURNjKZscblJxQOaQwrtFXDXcKPMfdSddEWlmoW2xcIDrahG X-Received: by 2002:aa7:cd54:: with SMTP id v20mr5081482edw.203.1573149899812; Thu, 07 Nov 2019 10:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573149899; cv=none; d=google.com; s=arc-20160816; b=xtvzWlVhgxIroiLl1oeuIvYsp2kq9sHYBdHEtBQb/EyAEPtHeTEAQQHNvi26HnaWWp 9Fa5Sa9cuAS7a53ZRCqSjwpItMcDhPMXdTuDGvyp9or+tnY+z9fi7dycec0T/pofc1ad fGo8qPKQPiJQj+3mcAKcM/ZhxYkc+xG96VUAIrCxROPBnS6ybWNWndaQWnPByhk1Ev/r EvL7ckwgFi6o9cKXbHj7W0YWwZIbtpgW8nFy8rOkS1frki3f2EswtGZCmvA3Pdee++Xf FI9/FzllS778lSfZt05ttbuDJ0PmcqkvDul4qmTF4zpwr8zWcK8SFJFnvbOc/2cfKRfG FcJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=3dxc8UFywmc4D1lU/tZVT7G/h73L1rjZRokkHWMynxg=; b=utigwdHzlWwT00+dHtdzaDKk7ldUdFJBGV57hD5jN5H4+D1V0+m02/MDjhE80ISHO9 6VR3ekFSdRBhUcgxOIW06hGHt7x15T0CBbBpZRzsAGUerjjiY1gad5enfU2fJKFtiUDE y9T7wdNzGFj0vcKMHs/gXsWWa3TwkgDFalCLjMrRT0gV9pG00x34YSjP5d7FVmk6wLvo SmeMYso89elv57lIRoCMtOFs7cPd7zMIrPEVpcG5iE+XDMphJu9OxdYpiP01XVMYmshC 13XrpDZjiU0UnnAG6d4xji8++s2zEaHM3QL4g9T1qdjpfQvnKYQ9dYYsdaQeUYVtvNXg /++w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6si1878675eji.80.2019.11.07.10.04.36; Thu, 07 Nov 2019 10:04:59 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725924AbfKGSCg (ORCPT + 99 others); Thu, 7 Nov 2019 13:02:36 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:48969 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725792AbfKGSCg (ORCPT ); Thu, 7 Nov 2019 13:02:36 -0500 Received: from p5b06da22.dip0.t-ipconnect.de ([91.6.218.34] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iSm77-0002uf-C2; Thu, 07 Nov 2019 19:02:33 +0100 Date: Thu, 7 Nov 2019 19:02:27 +0100 (CET) From: Thomas Gleixner To: Ingo Molnar cc: LKML , x86@kernel.org, Stephen Hemminger , Willy Tarreau , Juergen Gross , Sean Christopherson , Linus Torvalds , "H. Peter Anvin" Subject: Re: [patch 5/9] x86/ioport: Reduce ioperm impact for sane usage further In-Reply-To: <20191107081635.GE30739@gmail.com> Message-ID: References: <20191106193459.581614484@linutronix.de> <20191106202806.241007755@linutronix.de> <20191107081635.GE30739@gmail.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Nov 2019, Ingo Molnar wrote: > * Thomas Gleixner wrote: > This might seem like a small detail, but since we do the range tracking > and copying at byte granularity anyway, why not do the zero range search > at byte granularity as well? > > I bet it's faster and simpler as well than the bit-searching. Not necessarily. The bitmap search uses unsigned long internally at least to the point where it finds a zero bit. But probably we should just ditch that optimization and rather have the sequence number to figure out whether something needs to be copied at all. > > + if (first >= IO_BITMAP_BITS) { > > + /* > > + * If the resulting bitmap has all permissions dropped, clear > > + * TIF_IO_BITMAP and set the IO bitmap offset in the TSS to > > + * invalid. Deallocate both the new and the thread's bitmap. > > + */ > > + clear_thread_flag(TIF_IO_BITMAP); > > + tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_INVALID; > > + tofree = bitmap; > > + bitmap = NULL; > > BTW., wouldn't it be simpler to just say that if a thread uses IO ops > even once, it gets a bitmap and that's it? I.e. we could further simplify > this seldom used piece of code. Maybe. > > + } else { > > /* > > + * I/O bitmap contains zero bits. Set TIF_IO_BITMAP, make > > + * the bitmap offset valid and make sure that the TSS limit > > + * is correct. It might have been wreckaged by a VMEXiT. > > */ > > + set_thread_flag(TIF_IO_BITMAP); > > + tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_VALID; > > refresh_tss_limit(); > > } > > I'm wondering, shouldn't we call refresh_tss_limit() in both branches, or > is a VMEXIT-wreckaged TSS limit harmless if we otherwise have > io_bitmap_base set to IO_BITMAP_OFFSET_INVALID? Yes. because the VMEXIT wreckage restricts TSS limit to 0x67 which is the end of the hardware tss struct. As the invalid offset points in any case outside the TSS limit it does not matter. It always #GP's when an I/O access happens in user space. Thanks, tglx