From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C643C43603 for ; Wed, 18 Dec 2019 19:14:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 485E4218AC for ; Wed, 18 Dec 2019 19:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727121AbfLRTO5 (ORCPT ); Wed, 18 Dec 2019 14:14:57 -0500 Received: from mga18.intel.com ([134.134.136.126]:38112 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbfLRTO5 (ORCPT ); Wed, 18 Dec 2019 14:14:57 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:14:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="240892015" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga004.fm.intel.com with ESMTP; 18 Dec 2019 11:14:56 -0800 Date: Wed, 18 Dec 2019 11:14:55 -0800 From: Sean Christopherson To: Ben Gardon Cc: kvm@vger.kernel.org, Paolo Bonzini , Peter Feiner , Peter Shier , Junaid Shahid , Jim Mattson Subject: Re: [RFC PATCH 13/28] kvm: mmu: Add an iterator for concurrent paging structure walks Message-ID: <20191218191455.GD25201@linux.intel.com> References: <20190926231824.149014-1-bgardon@google.com> <20190926231824.149014-14-bgardon@google.com> <20191203021514.GK8120@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Dec 18, 2019 at 10:25:45AM -0800, Ben Gardon wrote: > On Mon, Dec 2, 2019 at 6:15 PM Sean Christopherson > wrote: > > > > > +static bool direct_walk_iterator_next_pte(struct direct_walk_iterator *iter) > > > +{ > > > + /* > > > + * This iterator could be iterating over a large number of PTEs, such > > > + * that if this thread did not yield, it would cause scheduler\ > > > + * problems. To avoid this, yield if needed. Note the check on > > > + * MMU_LOCK_MAY_RESCHED in direct_walk_iterator_cond_resched. This > > > + * iterator will not yield unless that flag is set in its lock_mode. > > > + */ > > > + direct_walk_iterator_cond_resched(iter); > > > > This looks very fragile, e.g. one of the future patches even has to avoid > > problems with this code by limiting the number of PTEs it processes. > > With this, functions either need to limit the number of PTEs they > process or pass the MMU_LOCK_MAY_RESCHED to the iterator. It would > probably be safer to invert the flag and make it > MMU_LOCK_MAY_NOT_RESCHED for functions that can self-regulate the > number of PTEs they process or have weird synchronization > requirements. For example, the page fault handler can't reschedule and > we know it won't process many entries, so we could pass > MMU_LOCK_MAY_NOT_RESCHED in there. That doesn't address the underlying fragility of the iterator, i.e. relying on callers to self-regulate. Especially since the threshold is completely arbitrary, e.g. in zap_direct_gfn_range(), what's to say PDPE and lower is always safe, e.g. if should_resched() becomes true at the very start of the walk? The direct comparison to zap_direct_gfn_range() is slot_handle_level_range(), which supports rescheduling regardless of what function is being invoked. What prevents the TDP iterator from doing the same? E.g. what's the worst case scenario if a reschedule pops up at an inopportune time?