Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp432121pxu; Wed, 14 Oct 2020 05:13:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7cobMHDCNljwZrBQYT/fTN4CU58pfo8Sl5FesV6k1TmczQkcbFoIWZvqc74zhCfUgT+fT X-Received: by 2002:a05:6402:392:: with SMTP id o18mr4907204edv.283.1602677615384; Wed, 14 Oct 2020 05:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602677615; cv=none; d=google.com; s=arc-20160816; b=u8agwHQGx1Qw2umOcBKeIxof1yoJL9QR4HFSeLierBf6hwksBnCFf1mUBSlzP3iG8Z qARQkFiXijD0JOlKa8ahNdM9ZzSNz2ZDwgf4ticht06j9SQPK2LMmkmFkgvZrvGfbL5Y n5RbWkBWAvg7iqEsv6SxnLmacXpMpg5fWrEiZhyvKoS1BsSpgsAL1MLV9Kvvm2GCKxEq q/MYV43ipOw9Opoi9CkEs1UtcBJG+qKO8ZxEBt7pSK75by4a8Pbjq9UU80qWqCazCK6I G4/SSxMeNgsb0VazVHbuzZ2evDtxiFRPEq3CHduFI7xc4H2kj3yJtfKDVcESHyrMFvc7 2lGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject:ironport-sdr:ironport-sdr; bh=ymdHMkbRScoraqtIKUSza0BTtscQV/fUNBl+43+Rsq0=; b=NooJHzcIZaxpbpxh+RqZ/32Vu9EQhJmIilJr14kAxsUptaM09JMHXo4tfYp3m0yCiC PwqijOMrSeweFp1KY6xys5s4IQ4n5orkaFSBdv8HXRtkas+LQnwvpM45QlfHdhCOuUDS 53FQ0bz6dlRWorRNdfPJDMAyQGACjkOstaSDawl4KDwQGRuJIz+foCCgSyRSRJiHnMhE M1pFx/6Cp/eNhoko9dlJDxKN9BrpcRH3h9dheICWdjF/gxr3KXPnuuloXuFmln74E46N UcK5JGkoQvXILvjp+GOPY9q6S8e8+Vw6Y1vuxsNxlFV1Mf3NyPDK+6OTmhd0mwe/UB9L k0Iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si1986679ejx.661.2020.10.14.05.13.05; Wed, 14 Oct 2020 05:13:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727112AbgJNGDE (ORCPT + 99 others); Wed, 14 Oct 2020 02:03:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:50171 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbgJNGDD (ORCPT ); Wed, 14 Oct 2020 02:03:03 -0400 IronPort-SDR: z9LmIVX4+1J+zPx3s0v+FOjBbtO/IA/T2jcLBlVO2MPxc8Zbzvm0Rtn+AsQ2DtbJJM+JUvje0y xgbulsZq7V3w== X-IronPort-AV: E=McAfee;i="6000,8403,9773"; a="152981074" X-IronPort-AV: E=Sophos;i="5.77,373,1596524400"; d="scan'208";a="152981074" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2020 23:03:03 -0700 IronPort-SDR: xx+Nl1AYmulD7/nlguq4O232Az5cnWWaOZiIWz2fr8+9RIWep27uRKNOnKj7+aHQPOKQDTNU73 hCMI89bv8YUg== X-IronPort-AV: E=Sophos;i="5.77,373,1596524400"; d="scan'208";a="463764697" Received: from kwhitemx-mobl.amr.corp.intel.com (HELO [10.213.181.206]) ([10.213.181.206]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2020 23:03:02 -0700 Subject: Re: [RFC PATCH 13/22] x86/fpu/xstate: Expand dynamic user state area on first use To: Andy Lutomirski Cc: "Brown, Len" , Andy Lutomirski , "Bae, Chang Seok" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , "Liu, Jing2" , "Shankar, Ravi V" , LKML References: <78F221DB-CB61-40DB-9C6F-6C86D0F1BCDF@amacapital.net> From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA/UORQWa1NiAftEoSpk5+nUUi0WE+5DRm0H+TXKBWMGNCFn c6+EKg5zQaa8KqymHcOrSXNPmzJuXvDQ8uj2J8XuzCZfK4uy1+YdIr0yyEMI7mdh4KX50LO1 pmowEqDh7dLShTOif/7UtQYrzYq9cPnjU2ZW4qd5Qz2joS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CY7ipLRORyalFDF3j5AGCMRENJjHPD6O7bl3Xo 4DzMID+8eucbXxKiNEbs21IqBZbbKdY1GkcEGTE7AnkA3Y6YB7I/j9mQ3hCgm5muJuhM/2Fr OPsw5tV/LmQ5GXH0JQ/TZXWygyRFyyI2FqNTx4WHqUn3yFj8rwTAU1tluRUYyeLy0ayUlKBH ybj0N71vWO936MqP6haFERzuPAIpxj2ezwu0xb1GjTk4ynna6h5GjnKgdfOWoRtoWndMZxbA z5cecg== Message-ID: <226772b9-7109-c632-2e9a-372df38b81a0@intel.com> Date: Tue, 13 Oct 2020 23:03:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <78F221DB-CB61-40DB-9C6F-6C86D0F1BCDF@amacapital.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/13/20 6:11 PM, Andy Lutomirski wrote: > I have no problem with vmalloc(), but I do have a problem with > vfree() due to the IPIs that result. We need a cache or something. This sounds like the kind of thing we should just build into vmalloc() instead of having a bunch of callers implement their own caches. It shouldn't be too much of a challenge to have vmalloc() keep a cacheline or two of stats about common vmalloc() sizes and keep some pools around. It's not going to be hard to implement caches to reduce vfree()-induced churn, but I'm having a hard time imaging that it'll have anywhere near the benefits that it did for stacks. Tasks fundamentally come and go a *lot*, and those paths are hot. Tasks who go to the trouble to populate 8k or 64k of register state fundamentally *can't* come and go frequently. We also (probably) don't have to worry about AMX tasks doing fork()/exec() pairs and putting pressure on vmalloc(). Before an app can call out to library functions to do the fork, they've got to save the state off themselves and likely get it back to the init state. The fork() code can tell AMX is in the init state and decline to allocate actual space for the child. > I have to say: this mechanism is awful. Can we get away with skipping > the dynamic XSAVES mess entirely? What if we instead allocate > however much space we need as an array of pages and have one percpu > contiguous region. To save, we XSAVE(S or C) just the AMX state to > the percpu area and then copy it. To restore, we do the inverse. Or > would this kill the modified optimization and thus be horrible? Actually, I think the modified optimization would survive such a scheme: * copy page array into percpu area * XRSTORS from percpu area, modified optimization tuple is saved * run userspace * XSAVES back to percpu area. tuple matches, modified optimization is still in play * copy percpu area back to page array Since the XRSTORS->XSAVES pair is both done to the percpu area, the XSAVE tracking hardware never knows it isn't working on the "canonical" buffer (the page array). It seems a bit ugly, but it's not like an 8k memcpy() is *that* painful. The double dcache footprint isn't super nice, though. Chang, I think that leaves us with three possibilities: 1. use plain old vmalloc() 2. use vmalloc(), but implement caches for large XSAVE state, either in front of, or inside the vmalloc() API 3. Use a static per-cpu buffer for XSAVE*/XRSTOR* and memcpy() to/from a scattered list of pages. A #4 also comes to mind: Do something somewhat like kmap_atomic(). Map the scattered pages contiguously and use XSAVE*/XRSTOR* directly, but unmap immediately after XSAVE*/XRSTOR*. For ~12k of state, I suspect the ~400-500 cycles for 3 INVLPG's might beat out a memcpy() of 12k of state. Global TLB invalidations would not be required. I have to say, though, that I'd be OK with sticking with plain old vmalloc() for now.