From patchwork Thu Jan 16 20:29:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11337759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9366D139A for ; Thu, 16 Jan 2020 20:31:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 6482B2073A for ; Thu, 16 Jan 2020 20:31:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KDOGuU7M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6482B2073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isBn8-0000QC-Aa; Thu, 16 Jan 2020 20:30:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isBn6-0000Q7-Lg for xen-devel@lists.xenproject.org; Thu, 16 Jan 2020 20:30:56 +0000 X-Inumbo-ID: 19299474-389f-11ea-ac27-bc764e2007e4 Received: from mail-qk1-x742.google.com (unknown [2607:f8b0:4864:20::742]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 19299474-389f-11ea-ac27-bc764e2007e4; Thu, 16 Jan 2020 20:30:56 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id w127so20478147qkb.11 for ; Thu, 16 Jan 2020 12:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yCqtrNWi/RM9EB7BrfRSR3dCdkeW7/TD3EjORCYLmHc=; b=KDOGuU7M6oOkZgvNLMQXlKxCe9RsBgpV1SjH1i9KOPQExkv9nPuxhLB59uAmxhw2YP Vkjjc+H5uzQ2Xyd551G831sCZmjb9HdC0o/SAetmI4kNj2qq5rb67aHPCCn4hdOvqUJr +qDxRNkgX6lXmeh8TfdPxQ8oe2b2O72EzJbHKNmAMlcuv6f6P8PUHkFzAYnE0fND6c/b otR+E3Ta+8gLNQ2PUvf2XlZFVdeX99BfAAbWGcsY4D+ZoJJfcev2nIxzI7zVpTFLeWhY 72oDrATPsQsdgAEBopVbyTr2yFfs4ZydvC5cOi05K7z3orRjiw9PF+NEIefVyYlU4C+U sLHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yCqtrNWi/RM9EB7BrfRSR3dCdkeW7/TD3EjORCYLmHc=; b=QznuJSXoAdx+b//bxwsKsmVvDmMrQtRUrCoPZQ8aY1F0LbQpWg6nRl/Fgy46YIftOO OpNn/n+WJSDX9v6rBROltLtkDA69UCfgb8hRBJcbBdZlY3lTaTq9ZEZzquI763t5DcVD /AMACmLNTxnW3vuaRuNt6teK6XJt7goEp5n/naJmRSYiSvMFsyriJaKoNqXDu8qnoLlP AbMrMf89cNom6dbNQrL3csvoi3YfhB6wMmTUaq9g/0PxnLth/BQO0j6SeN7BkWRzw+Ot YvjdtBfqH1/3BKs4TqiGhw+s2/W09XoaMTWZSofWWbZaC7dj/Z+U+Wn/Cc3dthEl0CVD dhCQ== X-Gm-Message-State: APjAAAUmyvRnFjN1McsUDCxcJABBQ4upUPlGSdMjJMpnNOT/tT8VtOXg R+277pPy0rRd+dFmwQi2p4UYP3MVoCo= X-Google-Smtp-Source: APXvYqzFyxBI4hBF8yjuyK11NgiYPHsNH/QiFq33d99JYnKj+dMegB5UKQbm63JlXwCM5WlgWIugJA== X-Received: by 2002:a37:a30a:: with SMTP id m10mr33470162qke.56.1579206655522; Thu, 16 Jan 2020 12:30:55 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:3c49:73c1:aa01:b504]) by smtp.gmail.com with ESMTPSA id s91sm11754808qtd.50.2020.01.16.12.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 12:30:54 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Date: Thu, 16 Jan 2020 15:29:26 -0500 Message-Id: <20200116202926.23230-1-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/shadow: use single (atomic) MOV for emulated writes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Jason Andryuk , George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is the corresponding change to the shadow code as made by bf08a8a08a2e "x86/HVM: use single (atomic) MOV for aligned emulated writes" to the non-shadow HVM code. The bf08a8a08a2e commit message: Using memcpy() may result in multiple individual byte accesses (depending how memcpy() is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back to memcpy() only for accesses not 2, 4, or 8 bytes in size. Signed-off-by: Jason Andryuk Acked-by: Tim Deegan --- xen/arch/x86/mm/shadow/hvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c index 48dfad4557..a219266fa2 100644 --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -215,7 +215,15 @@ hvm_emulate_write(enum x86_segment seg, return ~PTR_ERR(ptr); paging_lock(v->domain); - memcpy(ptr, p_data, bytes); + + /* Where possible use single (and hence generally atomic) MOV insns. */ + switch ( bytes ) + { + case 2: write_u16_atomic(ptr, *(uint16_t *)p_data); break; + case 4: write_u32_atomic(ptr, *(uint32_t *)p_data); break; + case 8: write_u64_atomic(ptr, *(uint64_t *)p_data); break; + default: memcpy(ptr, p_data, bytes); break; + } if ( tb_init_done ) v->arch.paging.mode->shadow.trace_emul_write_val(ptr, addr,