From patchwork Fri Apr 9 09:30:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 91668 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o399Qpuw013285 for ; Fri, 9 Apr 2010 09:26:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754913Ab0DIJ0t (ORCPT ); Fri, 9 Apr 2010 05:26:49 -0400 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:43998 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062Ab0DIJ0t (ORCPT ); Fri, 9 Apr 2010 05:26:49 -0400 Received: from serv2.oss.ntt.co.jp (localhost [127.0.0.1]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 24B4B24826C; Fri, 9 Apr 2010 18:26:48 +0900 (JST) Received: from serv1.oss.ntt.co.jp (serv1.oss.ntt.co.jp [172.19.0.2]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 1225B248243; Fri, 9 Apr 2010 18:26:48 +0900 (JST) Received: from yshtky3.kern.oss.ntt.co.jp (unknown [172.17.1.110]) by serv1.oss.ntt.co.jp (Postfix) with SMTP id E747D11C111; Fri, 9 Apr 2010 18:26:47 +0900 (JST) Date: Fri, 9 Apr 2010 18:30:21 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, fernando@oss.ntt.co.jp Subject: [PATCH RFC 1/5] KVM: introduce a set_bit function for bitmaps in user space Message-Id: <20100409183021.843ca432.yoshikawa.takuya@oss.ntt.co.jp> In-Reply-To: <20100409182732.857de4db.yoshikawa.takuya@oss.ntt.co.jp> References: <20100409182732.857de4db.yoshikawa.takuya@oss.ntt.co.jp> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 09 Apr 2010 09:26:58 +0000 (UTC) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index abd3e0e..25a694e 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -98,6 +98,43 @@ struct exception_table_entry { extern int fixup_exception(struct pt_regs *regs); +/** + * set_bit_user: - Set a bit of a bitmap in user space. + * @nr: Bit offset to set. + * @addr: Base address, in user space. + * + * Context: User context only. This function may sleep. + * + * This macro sets a bit of a bitmap in user space. Note that this + * is same as __set_bit but not set_bit in the sense that setting + * the bit is not done atomically. + * + * Returns zero on success, -EFAULT on error. + */ +#define __set_bit_user_asm(nr, addr, err, errret) \ + asm volatile("1: bts %1,%2\n" \ + "2:\n" \ + ".section .fixup,\"ax\"\n" \ + "3: mov %3,%0\n" \ + " jmp 2b\n" \ + ".previous\n" \ + _ASM_EXTABLE(1b, 3b) \ + : "=r"(err) \ + : "r" (nr), "m" (__m(addr)), "i" (errret), "0" (err)) + +#define set_bit_user(nr, addr) \ +({ \ + int __ret_sbu = 0; \ + \ + might_fault(); \ + if (access_ok(VERIFY_WRITE, addr, nr/8 + 1)) \ + __set_bit_user_asm(nr, addr, __ret_sbu, -EFAULT); \ + else \ + __ret_sbu = -EFAULT; \ + \ + __ret_sbu; \ +}) + /* * These are the main single-value transfer routines. They automatically * use the right size if we just have the right pointer type.