Received: by 10.213.65.68 with SMTP id h4csp1809609imn; Mon, 19 Mar 2018 13:55:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELtVa1Hw3jpBcbUjse3KgfHwSzWEaM9mQtREkLr5Q/v3AdpiGPgfMXR19wMm+u3IfS/oeEmM X-Received: by 10.99.115.84 with SMTP id d20mr10209510pgn.362.1521492936854; Mon, 19 Mar 2018 13:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521492936; cv=none; d=google.com; s=arc-20160816; b=qV5JFjedeEt6uE2qXdserJvMGkmmAwwvC/c/9lzUR4xm7IJSZBVvIWbBIEEfIfC6wL veZ5xFQ2dfIlOHFcVgyjLzWe7UU+jUSdSW4lsn2PE0qxZkLxzYb0mpHgVvp5PvXpbuvn Jrje6eFJIzmnGmHbuYjs0gGrc+hmgBzwaoxI5Z+anaJ9Qx6HubHhLnhfF5skrtMzgoLD em0e7aSxS4W4Bg0q2GmKWHv1ia2IcqI00h4jAVwFvZIuQJ63y4JfUKJtY7C1z4Cm4d04 LRC5AjedyMcpAL5KaO9cquaO/JUt2BSiCrVFJw6UmhYTsjPWb3tG3w/NWVgZZsApgtC3 YGeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=adJmxo0CrWqBUG/d/m6P7p+vd4hzZAFKowQhWgwvJRo=; b=coKbgSEQKY2z1amD2G5ke8VQAy38C34P70MwFDzIuCcrV1bjDP+Dnc2JD0PXyAP7KJ n3sUDH5fCXjj0modN7N+vT+WijOEVuJI9bkGbidhgmtlAN/nMRl/PgLOzXF2u2iW4VON h75dW+z96ttAARN0vZRtiGrs2O/SW0LkD1H5ol011KWYXIHBJHNj7u21Sw+y/Y2bNhE5 mYRN6Xz+csEFqAr1MNl4bBlQwfnG0HrJsxX4cBi1Rp63BMflQ7cb5t//vxL1TO0zYCn3 ha2ri8hH80hM4PWxMYyzx1A8T05m3GQbd65ku7/4e3Q8Y5QbgdosbSqwzSDufFXdia1L N9PQ== 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 t75si71048pgc.156.2018.03.19.13.55.22; Mon, 19 Mar 2018 13:55:36 -0700 (PDT) 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 S968559AbeCSSI6 (ORCPT + 99 others); Mon, 19 Mar 2018 14:08:58 -0400 Received: from mga14.intel.com ([192.55.52.115]:62509 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968518AbeCSSIx (ORCPT ); Mon, 19 Mar 2018 14:08:53 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2018 11:08:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,331,1517904000"; d="scan'208";a="39330576" Received: from chang-linux.sc.intel.com ([143.183.85.144]) by fmsmga001.fm.intel.com with ESMTP; 19 Mar 2018 11:08:51 -0700 From: "Chang S. Bae" To: x86@kernel.org Cc: luto@kernel.org, ak@linux.intel.com, hpa@zytor.com, markus.t.metzger@intel.com, tony.luck@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com Subject: [PATCH 06/15] x86/fsgsbase/64: Add putregs() to handle multiple elements' setting Date: Mon, 19 Mar 2018 10:49:18 -0700 Message-Id: <1521481767-22113-7-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> References: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org putregs() can be used to handle multiple elements flexibly. It is useful when inter-dependency lies in updating a group of context entries. There will be a case with FSGSBASE. Signed-off-by: Chang S. Bae Cc: Markus T. Metzger Cc: H. Peter Anvin Cc: Andi Kleen Cc: Andy Lutomirski --- arch/x86/kernel/ptrace.c | 51 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index d8a1e1b..9c09bf0 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -421,6 +421,22 @@ static int putreg(struct task_struct *child, return 0; } +static int putregs(struct task_struct *child, + unsigned int offset, + unsigned int count, + const unsigned long *values) +{ + const unsigned long *v = values; + int ret = 0; + + while (count >= sizeof(*v) && !ret) { + ret = putreg(child, offset, *v++); + count -= sizeof(*v); + offset += sizeof(*v); + } + return ret; +} + static unsigned long getreg(struct task_struct *task, unsigned long offset) { switch (offset) { @@ -477,24 +493,37 @@ static int genregs_set(struct task_struct *target, const void *kbuf, const void __user *ubuf) { int ret = 0; + if (kbuf) { - const unsigned long *k = kbuf; - while (count >= sizeof(*k) && !ret) { - ret = putreg(target, pos, *k++); - count -= sizeof(*k); - pos += sizeof(*k); - } + ret = putregs(target, pos, count, kbuf); } else { const unsigned long __user *u = ubuf; - while (count >= sizeof(*u) && !ret) { + const unsigned long *genregs = NULL; + unsigned long *buf = NULL; + unsigned int remains = 0; + + buf = kmalloc(count, GFP_KERNEL); + + if (unlikely(!buf)) + return -ENOMEM; + + genregs = buf; + remains = count; + + while (remains >= sizeof(*u) && !ret) { unsigned long word; + ret = __get_user(word, u++); - if (ret) + if (unlikely(ret)) break; - ret = putreg(target, pos, word); - count -= sizeof(*u); - pos += sizeof(*u); + memcpy(buf++, &word, sizeof(*u)); + remains -= sizeof(*u); } + + if (likely(!ret)) + /* Allows to handle multiple elements accordingly. */ + ret = putregs(target, pos, count, genregs); + kfree(genregs); } return ret; } -- 2.7.4