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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 135EDC433E0 for ; Sun, 10 Jan 2021 18:40:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A15A22AAA for ; Sun, 10 Jan 2021 18:40:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A15A22AAA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyfdx-0002K3-Cv for qemu-devel@archiver.kernel.org; Sun, 10 Jan 2021 13:40:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyfbv-0001sh-Qf for qemu-devel@nongnu.org; Sun, 10 Jan 2021 13:38:43 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:34655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kyfbu-0002Jy-CF for qemu-devel@nongnu.org; Sun, 10 Jan 2021 13:38:43 -0500 Received: by mail-pl1-x632.google.com with SMTP id t6so8339690plq.1 for ; Sun, 10 Jan 2021 10:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FO/HyCvLsxofLpoWFNpy0PrFoKfOdbv8M9gG/dRNdy4=; b=qy8xxY1apgDNBgzybRmj3P0vS5jvV6j0PZfd/wUGi4crNT3oSBnIsW5fmpybd854rW nwRfnGu625cKxeiaS1nptIN3vD/pNB6SWrwYIaec5GUn1H4zd23fMTJ6fJlSiAr/zTlY mPpWir0oHo+l9tUWD8ZlY9RsY6Is/t+Zj/NwhZ6N3PwHQFZdOjeFIx0VCPw25qvuICPa 89KCgryRIJN1IXyzmP/CNOP/gDOw8L6NpZ/kUUogzcBl6aOPeWACj3PfIAKQ5+a5KXcf 9nXhGUJSG9iMjhTLIbeGFts+4WucHKXm/s47bmIg1gFKxjNwINZZjqikwmzpkt6qFJDM p+Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FO/HyCvLsxofLpoWFNpy0PrFoKfOdbv8M9gG/dRNdy4=; b=WUeWXE/JUyTyvFB6MNeRC00w5u8Ag6zNCHSP42/7afaQtlpv3hRFu/5CqoOnLEleGz 5Qr9l9eu8q00C6QRvq96CdtizkBOfUGqy6QkWabEM5PTToGPN1tk85Xn/mt1MVHCJXxL laSf8QhwsW3i7G7buyD5VYHVIk8Fz7sal7ry1G+vqIYDkzuYAngeGIpR4LtiS+QWWZM4 NElrRoQB/NFRAmN3OhPvvMAztjOsVUwbmJ5KjOUE17v7oYGrDU/EdeFv+Tah3T5Bfesy g40zBfq6eYHceSA8LfaZ9vpzDiaWwOs6qgy7GO0sdGfQquIiCEzXgDAhfZZ2jVEqi0f6 7Q3A== X-Gm-Message-State: AOAM532ys8mUT1B7wlHP7fkaM6mJCLKh+MuhNYlnkJtUVxoUxC0a8e2z Fko8kehuxU8aj8nY8b+TFqiyLg== X-Google-Smtp-Source: ABdhPJwZLQD9hukSWh//3veL8M3jkcTMFqkOaPsW8aI9+eUefI5OOXvHW0bBt/bKR0hfVaxhsOaVOA== X-Received: by 2002:a17:90a:708b:: with SMTP id g11mr13700180pjk.23.1610303920910; Sun, 10 Jan 2021 10:38:40 -0800 (PST) Received: from [10.25.18.117] (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id y16sm16774308pfb.83.2021.01.10.10.38.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Jan 2021 10:38:40 -0800 (PST) Subject: Re: [PATCH] hvf: guard xgetbv call. To: Roman Bolshakov , Peter Maydell , Hill Ma References: <8da22f7f-7379-cffe-5fdd-94fd5ddece32@linaro.org> From: Richard Henderson Message-ID: <4a24ae1a-8114-a840-b6bf-ae3a301f6232@linaro.org> Date: Sun, 10 Jan 2021 08:38:36 -1000 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: <8da22f7f-7379-cffe-5fdd-94fd5ddece32@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.012, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Richard Henderson , QEMU Developers , Cameron Esfahani , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 1/10/21 8:34 AM, Richard Henderson wrote: > On 1/9/21 3:46 PM, Roman Bolshakov wrote: >> +static int xgetbv(uint32_t cpuid_ecx, uint32_t idx, uint64_t *xcr) >> { >> - uint32_t eax, edx; >> + uint32_t xcrl, xcrh; >> >> - __asm__ volatile ("xgetbv" >> - : "=a" (eax), "=d" (edx) >> - : "c" (xcr)); >> + if (cpuid_ecx && CPUID_EXT_OSXSAVE) { >> + /* The xgetbv instruction is not available to older versions of >> + * the assembler, so we encode the instruction manually. >> + */ >> + asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcrl), "=d" (xcrh) : "c" (idx)); >> >> - return (((uint64_t)edx) << 32) | eax; >> + *xcr = (((uint64_t)xcrh) << 32) | xcrl; >> + return 0; >> + } >> + >> + return 1; >> } > > Not to bikeshed too much, but this looks like it should return bool, and true > on success, not the other way around. Also, if we're going to put this some place common, forcing the caller to do the cpuid that feeds this, then we should probably make all of the startup cpuid stuff common as well. Note that we'd probably have to use constructor priorities to get that right for util/bufferiszero.c. r~