From owner-svn-src-projects@FreeBSD.ORG Fri Oct 19 09:14:19 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EA96E15A for ; Fri, 19 Oct 2012 09:14:19 +0000 (UTC) (envelope-from andre@freebsd.org) Received: from c00l3r.networx.ch (c00l3r.networx.ch [62.48.2.2]) by mx1.freebsd.org (Postfix) with ESMTP id 43F6C8FC0C for ; Fri, 19 Oct 2012 09:14:18 +0000 (UTC) Received: (qmail 29852 invoked from network); 19 Oct 2012 10:52:58 -0000 Received: from c00l3r.networx.ch (HELO [127.0.0.1]) ([62.48.2.2]) (envelope-sender ) by c00l3r.networx.ch (qmail-ldap-1.03) with SMTP for ; 19 Oct 2012 10:52:58 -0000 Message-ID: <508119DE.6020106@freebsd.org> Date: Fri, 19 Oct 2012 11:14:06 +0200 From: Andre Oppermann User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: John Baldwin Subject: Re: svn commit: r238907 - projects/calloutng/sys/kern References: <201207301350.q6UDobCI099069@svn.freebsd.org> <5056D078.3020904@freebsd.org> <201209171113.06861.jhb@freebsd.org> In-Reply-To: <201209171113.06861.jhb@freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Davide Italiano , mlaier@freebsd.org, svn-src-projects@freebsd.org, attilio@freebsd.org, Konstantin Belousov , src-committers@freebsd.org, Stephan Uphoff X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Oct 2012 09:14:20 -0000 On 17.09.2012 17:13, John Baldwin wrote: > On Monday, September 17, 2012 3:25:44 am Andre Oppermann wrote: >> Hello Attilio, >> >> could you integrate and test this patch from Isilon as well: >> >> Add INVARIANT and WITNESS support to rm_lock locks and optimize the >> synchronization path by replacing a LIST of active readers with a >> TAILQ. >> >> Obtained from: Isilon >> Submitted by: mlaier >> >> http://svn.freebsd.org/changeset/base/234648 >> >> You're far deeper into locking than I am. > > Some of this is already in the tree, and their WITNESS changes don't quite > work correctly. I have several fixes (including some of these already) that I > am just waiting to develop a good test for. Having an _rm_assert() to pull > from will be good though. Any news/progress on this? -- Andre From owner-svn-src-projects@FreeBSD.ORG Fri Oct 19 09:21:25 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3D7034D3; Fri, 19 Oct 2012 09:21:25 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 802208FC18; Fri, 19 Oct 2012 09:21:23 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id e12so196875lag.13 for ; Fri, 19 Oct 2012 02:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=9bzJTe2eb6OTazQO0ln4Q6JMv0kJpB24j7K/j6Zzc3A=; b=oUOKED63Zk8JJ5oR3ZmtuGZTMaztxxxfLf9/q7fLLD3//eE0+v+D0RJ4WpWesHOYV0 zgO7bvFLOpqFH8PjTdMApVEq6rXMkoo/TGmBDSnileUqe19WjUeG5/V7QaGcJlC8PxLl PegyBv81Tu2BTLZ0CPptRMo3DJDSphyL28ktUclwfXt362l6VsGMYixoQGFBD5qye2KG ZNuRh5a5MyDqx5Yjqcf85GAUz6w70kYNXWxy39L9AeuF/fSsXjWABQ1jqsV0+Hglf+wY BdJGisqzVDUdSzRtjDF9co6Mx+rQREDiAepFOGfenppdTfe269QMoo4Zrr6pkViFXaW4 8nRQ== MIME-Version: 1.0 Received: by 10.112.98.37 with SMTP id ef5mr381923lbb.84.1350638481520; Fri, 19 Oct 2012 02:21:21 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.112.30.37 with HTTP; Fri, 19 Oct 2012 02:21:21 -0700 (PDT) In-Reply-To: <508119DE.6020106@freebsd.org> References: <201207301350.q6UDobCI099069@svn.freebsd.org> <5056D078.3020904@freebsd.org> <201209171113.06861.jhb@freebsd.org> <508119DE.6020106@freebsd.org> Date: Fri, 19 Oct 2012 10:21:21 +0100 X-Google-Sender-Auth: Th_yYq1IVPteuiaA6MKEkbu6wxU Message-ID: Subject: Re: svn commit: r238907 - projects/calloutng/sys/kern From: Attilio Rao To: Andre Oppermann Content-Type: text/plain; charset=UTF-8 Cc: Davide Italiano , mlaier@freebsd.org, svn-src-projects@freebsd.org, John Baldwin , Konstantin Belousov , src-committers@freebsd.org, Stephan Uphoff X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Oct 2012 09:21:25 -0000 On 10/19/12, Andre Oppermann wrote: > On 17.09.2012 17:13, John Baldwin wrote: >> On Monday, September 17, 2012 3:25:44 am Andre Oppermann wrote: >>> Hello Attilio, >>> >>> could you integrate and test this patch from Isilon as well: >>> >>> Add INVARIANT and WITNESS support to rm_lock locks and optimize the >>> synchronization path by replacing a LIST of active readers with a >>> TAILQ. >>> >>> Obtained from: Isilon >>> Submitted by: mlaier >>> >>> http://svn.freebsd.org/changeset/base/234648 >>> >>> You're far deeper into locking than I am. >> >> Some of this is already in the tree, and their WITNESS changes don't >> quite >> work correctly. I have several fixes (including some of these already) >> that I >> am just waiting to develop a good test for. Having an _rm_assert() to >> pull >> from will be good though. > > Any news/progress on this? I left the ball to John, but I can intervein if needed. Attilio -- Peace can only be achieved by understanding - A. Einstein From owner-svn-src-projects@FreeBSD.ORG Fri Oct 19 18:11:18 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8E51B45C; Fri, 19 Oct 2012 18:11:18 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 756448FC08; Fri, 19 Oct 2012 18:11:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9JIBIxp049367; Fri, 19 Oct 2012 18:11:18 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9JIBIQu049356; Fri, 19 Oct 2012 18:11:18 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201210191811.q9JIBIQu049356@svn.freebsd.org> From: Peter Grehan Date: Fri, 19 Oct 2012 18:11:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r241744 - projects/bhyve/usr.sbin/bhyve X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Oct 2012 18:11:18 -0000 Author: grehan Date: Fri Oct 19 18:11:17 2012 New Revision: 241744 URL: http://svn.freebsd.org/changeset/base/241744 Log: Rework how guest MMIO regions are dealt with. - New memory region interface. An RB tree holds the regions, with a last-found per-vCPU cache to deal with the common case of repeated guest accesses to MMIO registers in the same page. - Support memory-mapped BARs in PCI emulation. mem.c/h - memory region interface instruction_emul.c/h - remove old region interface. Use gpa from EPT exit to avoid a tablewalk to determine operand address. Determine operand size and use when calling through to region handler. fbsdrun.c - call into region interface on paging exit. Distinguish between instruction emul error and region not found pci_emul.c/h - implement new BAR callback api. Split BAR alloc routine into routines that require/don't require the BAR phys address. ioapic.c pci_passthru.c pci_virtio_block.c pci_virtio_net.c pci_uart.c - update to new BAR callback i/f Reviewed by: neel Obtained from: NetApp Added: projects/bhyve/usr.sbin/bhyve/mem.c (contents, props changed) projects/bhyve/usr.sbin/bhyve/mem.h (contents, props changed) Modified: projects/bhyve/usr.sbin/bhyve/Makefile projects/bhyve/usr.sbin/bhyve/fbsdrun.c projects/bhyve/usr.sbin/bhyve/instruction_emul.c projects/bhyve/usr.sbin/bhyve/instruction_emul.h projects/bhyve/usr.sbin/bhyve/ioapic.c projects/bhyve/usr.sbin/bhyve/pci_emul.c projects/bhyve/usr.sbin/bhyve/pci_emul.h projects/bhyve/usr.sbin/bhyve/pci_passthru.c projects/bhyve/usr.sbin/bhyve/pci_uart.c projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c projects/bhyve/usr.sbin/bhyve/pci_virtio_net.c Modified: projects/bhyve/usr.sbin/bhyve/Makefile ============================================================================== --- projects/bhyve/usr.sbin/bhyve/Makefile Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/Makefile Fri Oct 19 18:11:17 2012 (r241744) @@ -5,7 +5,7 @@ PROG= bhyve SRCS= atpic.c consport.c dbgport.c elcr.c fbsdrun.c inout.c -SRCS+= instruction_emul.c ioapic.c mevent.c +SRCS+= instruction_emul.c ioapic.c mem.c mevent.c SRCS+= pci_emul.c pci_hostbridge.c pci_passthru.c pci_virtio_block.c SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c post.c rtc.c uart.c xmsr.c SRCS+= spinup_ap.c Modified: projects/bhyve/usr.sbin/bhyve/fbsdrun.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/fbsdrun.c Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/fbsdrun.c Fri Oct 19 18:11:17 2012 (r241744) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include "fbsdrun.h" #include "inout.h" #include "dbgport.h" +#include "mem.h" #include "mevent.h" #include "pci_emul.h" #include "xmsr.h" @@ -446,11 +447,21 @@ vmexit_mtrap(struct vmctx *ctx, struct v static int vmexit_paging(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) { - + int err; stats.vmexit_paging++; - if (emulate_instruction(ctx, *pvcpu, vmexit->rip, vmexit->u.paging.cr3) != 0) { - printf("Failed to emulate instruction at 0x%lx\n", vmexit->rip); + err = emulate_mem(ctx, *pvcpu, vmexit->u.paging.gpa, vmexit->rip, + vmexit->u.paging.cr3, vmexit->u.paging.rwx); + + if (err) { + if (err == EINVAL) { + printf("Failed to emulate instruction at 0x%lx\n", + vmexit->rip); + } else if (err == ESRCH) { + printf("Unhandled memory access to 0x%lx\n", + vmexit->u.paging.gpa); + } + return (VMEXIT_ABORT); } Modified: projects/bhyve/usr.sbin/bhyve/instruction_emul.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/instruction_emul.c Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/instruction_emul.c Fri Oct 19 18:11:17 2012 (r241744) @@ -28,10 +28,12 @@ #include #include +#include #include #include #include "fbsdrun.h" +#include "mem.h" #include "instruction_emul.h" #define PREFIX_LOCK 0xF0 @@ -46,6 +48,7 @@ #define PREFIX_BRANCH_NOT_TAKEN 0x2E #define PREFIX_BRANCH_TAKEN 0x3E #define PREFIX_OPSIZE 0x66 +#define is_opsz_prefix(x) ((x) == PREFIX_OPSIZE) #define PREFIX_ADDRSIZE 0x67 #define OPCODE_2BYTE_ESCAPE 0x0F @@ -95,6 +98,11 @@ #define FROM_REG (1<<2) #define TO_RM (1<<3) #define TO_REG (1<<4) +#define ZEXT (1<<5) +#define FROM_8 (1<<6) +#define FROM_16 (1<<7) +#define TO_8 (1<<8) +#define TO_16 (1<<9) #define REX_MASK 0xF0 #define REX_PREFIX 0x40 @@ -118,16 +126,7 @@ #define PML4E_OFFSET_MASK 0x0000FF8000000000 #define PML4E_SHIFT 39 -#define MAX_EMULATED_REGIONS 8 -int registered_regions = 0; -struct memory_region -{ - uintptr_t start; - uintptr_t end; - emulated_read_func_t memread; - emulated_write_func_t memwrite; - void *arg; -} emulated_regions[MAX_EMULATED_REGIONS]; +#define INSTR_VERIFY struct decoded_instruction { @@ -138,11 +137,12 @@ struct decoded_instruction uint8_t *displacement; uint8_t *immediate; - uint8_t opcode_flags; + uint16_t opcode_flags; uint8_t addressing_mode; uint8_t rm; uint8_t reg; + uint8_t opsz; uint8_t rex_r; uint8_t rex_w; uint8_t rex_b; @@ -170,11 +170,17 @@ static enum vm_reg_name vm_reg_name_mapp [REG_R15] = VM_REG_GUEST_R15 }; -uint8_t one_byte_opcodes[256] = { - [0x89] = HAS_MODRM | FROM_REG | TO_RM, +uint16_t one_byte_opcodes[256] = { + [0x88] = HAS_MODRM | FROM_REG | TO_RM | TO_8 | FROM_8, + [0x89] = HAS_MODRM | FROM_REG | TO_RM, [0x8B] = HAS_MODRM | FROM_RM | TO_REG, }; +uint16_t two_byte_opcodes[256] = { + [0xB6] = HAS_MODRM | FROM_RM | TO_REG | ZEXT | FROM_8, + [0xB7] = HAS_MODRM | FROM_RM | TO_REG | ZEXT | FROM_16, +}; + static uintptr_t gla2gpa(uint64_t gla, uint64_t guest_cr3) { @@ -211,7 +217,8 @@ gla2hla(uint64_t gla, uint64_t guest_cr3 uintptr_t gpa; gpa = gla2gpa(gla, guest_cr3); - return paddr_guest2host(gpa); + + return (paddr_guest2host(gpa)); } /* @@ -232,6 +239,9 @@ decode_prefixes(struct decoded_instructi decoded->rex_x = *current_prefix & REX_X_MASK; decoded->rex_b = *current_prefix & REX_B_MASK; current_prefix++; + } else if (is_opsz_prefix(*current_prefix)) { + decoded->opsz = 1; + current_prefix++; } else if (is_prefix(*current_prefix)) { return (-1); } @@ -248,16 +258,26 @@ decode_prefixes(struct decoded_instructi static int decode_opcode(struct decoded_instruction *decoded) { - uint8_t opcode, flags; + uint8_t opcode; + uint16_t flags; + int extra; opcode = *decoded->opcode; - flags = one_byte_opcodes[opcode]; + extra = 0; + if (opcode != 0xf) + flags = one_byte_opcodes[opcode]; + else { + opcode = *(decoded->opcode + 1); + flags = two_byte_opcodes[opcode]; + extra = 1; + } + if (!flags) return (-1); if (flags & HAS_MODRM) { - decoded->modrm = decoded->opcode + 1; + decoded->modrm = decoded->opcode + 1 + extra; } decoded->opcode_flags = flags; @@ -381,37 +401,70 @@ decode_instruction(void *instr, struct d return (0); } -static struct memory_region * -find_region(uintptr_t addr) +static enum vm_reg_name +get_vm_reg_name(uint8_t reg) { - int i; - for (i = 0; i < registered_regions; ++i) { - if (emulated_regions[i].start <= addr && - emulated_regions[i].end >= addr) { - return &emulated_regions[i]; - } - } - - return (0); + return (vm_reg_name_mappings[reg]); } -static enum vm_reg_name -get_vm_reg_name(uint8_t reg) +static uint64_t +adjust_operand(const struct decoded_instruction *instruction, uint64_t val, + int size) { - return vm_reg_name_mappings[reg]; + uint64_t ret; + + if (instruction->opcode_flags & ZEXT) { + switch (size) { + case 1: + ret = val & 0xff; + break; + case 2: + ret = val & 0xffff; + break; + case 4: + ret = val & 0xffffffff; + break; + case 8: + ret = val; + break; + default: + break; + } + } else { + /* + * Extend the sign + */ + switch (size) { + case 1: + ret = (int8_t)(val & 0xff); + break; + case 2: + ret = (int16_t)(val & 0xffff); + break; + case 4: + ret = (int32_t)(val & 0xffffffff); + break; + case 8: + ret = val; + break; + default: + break; + } + } + + return (ret); } static int -get_operand(struct vmctx *vm, int vcpu, uint64_t guest_cr3, - const struct decoded_instruction *instruction, uint64_t *operand) +get_operand(struct vmctx *vm, int vcpu, uint64_t gpa, uint64_t guest_cr3, + const struct decoded_instruction *instruction, uint64_t *operand, + struct mem_range *mr) { enum vm_reg_name regname; uint64_t reg; - uintptr_t target; int error; - uint8_t rm, addressing_mode; - struct memory_region *emulated_memory; + uint8_t rm, addressing_mode, size; if (instruction->opcode_flags & FROM_RM) { rm = instruction->rm; @@ -422,6 +475,17 @@ get_operand(struct vmctx *vm, int vcpu, } else return (-1); + /* + * Determine size of operand + */ + size = 4; + if (instruction->opcode_flags & FROM_8) { + size = 1; + } else if (instruction->opcode_flags & FROM_16 || + instruction->opsz) { + size = 2; + } + regname = get_vm_reg_name(rm); error = vm_get_register(vm, vcpu, regname, ®); if (error) @@ -430,33 +494,67 @@ get_operand(struct vmctx *vm, int vcpu, switch (addressing_mode) { case MOD_DIRECT: *operand = reg; - return (0); + error = 0; + break; case MOD_INDIRECT: case MOD_INDIRECT_DISP8: case MOD_INDIRECT_DISP32: +#ifdef INSTR_VERIFY + { + uintptr_t target; + target = gla2gpa(reg, guest_cr3); target += instruction->disp; - emulated_memory = find_region(target); - if (emulated_memory) { - return emulated_memory->memread(vm, vcpu, target, - 4, operand, - emulated_memory->arg); - } - return (-1); + assert(gpa == target); + } +#endif + error = (*mr->handler)(vm, vcpu, MEM_F_READ, gpa, size, + operand, mr->arg1, mr->arg2); + break; default: return (-1); } + + if (!error) + *operand = adjust_operand(instruction, *operand, size); + + return (error); +} + +static uint64_t +adjust_write(uint64_t reg, uint64_t operand, int size) +{ + uint64_t val; + + switch (size) { + case 1: + val = (reg & ~0xff) | (operand & 0xff); + break; + case 2: + val = (reg & ~0xffff) | (operand & 0xffff); + break; + case 4: + val = (reg & ~0xffffffff) | (operand & 0xffffffff); + break; + case 8: + val = operand; + default: + break; + } + + return (val); } static int -perform_write(struct vmctx *vm, int vcpu, uint64_t guest_cr3, - const struct decoded_instruction *instruction, uint64_t operand) +perform_write(struct vmctx *vm, int vcpu, uint64_t gpa, uint64_t guest_cr3, + const struct decoded_instruction *instruction, uint64_t operand, + struct mem_range *mr) { enum vm_reg_name regname; uintptr_t target; int error; + int size; uint64_t reg; - struct memory_region *emulated_memory; uint8_t addressing_mode; if (instruction->opcode_flags & TO_RM) { @@ -467,83 +565,77 @@ perform_write(struct vmctx *vm, int vcpu addressing_mode = MOD_DIRECT; } else return (-1); - - regname = get_vm_reg_name(reg); - error = vm_get_register(vm, vcpu, regname, ®); - if (error) - return (error); - + + /* + * Determine the operand size. rex.w has priority + */ + size = 4; + if (instruction->rex_w) { + size = 8; + } else if (instruction->opcode_flags & TO_8) { + size = 1; + } else if (instruction->opsz) { + size = 2; + }; + switch(addressing_mode) { case MOD_DIRECT: - return vm_set_register(vm, vcpu, regname, operand); + regname = get_vm_reg_name(reg); + error = vm_get_register(vm, vcpu, regname, ®); + if (error) + return (error); + operand = adjust_write(reg, operand, size); + + return (vm_set_register(vm, vcpu, regname, operand)); case MOD_INDIRECT: case MOD_INDIRECT_DISP8: case MOD_INDIRECT_DISP32: +#ifdef INSTR_VERIFY + regname = get_vm_reg_name(reg); + error = vm_get_register(vm, vcpu, regname, ®); + assert(!error); target = gla2gpa(reg, guest_cr3); target += instruction->disp; - emulated_memory = find_region(target); - if (emulated_memory) { - return emulated_memory->memwrite(vm, vcpu, target, - 4, operand, - emulated_memory->arg); - } - return (-1); + assert(gpa == target); +#endif + error = (*mr->handler)(vm, vcpu, MEM_F_WRITE, gpa, size, + &operand, mr->arg1, mr->arg2); + return (error); default: return (-1); } } static int -emulate_decoded_instruction(struct vmctx *vm, int vcpu, uint64_t cr3, - const struct decoded_instruction *instruction) +emulate_decoded_instruction(struct vmctx *vm, int vcpu, uint64_t gpa, + uint64_t cr3, + const struct decoded_instruction *instruction, + struct mem_range *mr) { uint64_t operand; int error; - error = get_operand(vm, vcpu, cr3, instruction, &operand); + error = get_operand(vm, vcpu, gpa, cr3, instruction, &operand, mr); if (error) return (error); - return perform_write(vm, vcpu, cr3, instruction, operand); + return perform_write(vm, vcpu, gpa, cr3, instruction, operand, mr); } -int -emulate_instruction(struct vmctx *vm, int vcpu, uint64_t rip, uint64_t cr3) +int +emulate_instruction(struct vmctx *vm, int vcpu, uint64_t rip, uint64_t cr3, + uint64_t gpa, int flags, struct mem_range *mr) { struct decoded_instruction instr; int error; - void *instruction = gla2hla(rip, cr3); - - if ((error = decode_instruction(instruction, &instr)) != 0) - return (error); - - return emulate_decoded_instruction(vm, vcpu, cr3, &instr); -} - -struct memory_region * -register_emulated_memory(uintptr_t start, size_t len, emulated_read_func_t memread, - emulated_write_func_t memwrite, void *arg) -{ - if (registered_regions >= MAX_EMULATED_REGIONS) - return (NULL); - - struct memory_region *region = &emulated_regions[registered_regions]; - region->start = start; - region->end = start + len; - region->memread = memread; - region->memwrite = memwrite; - region->arg = arg; + void *instruction; - registered_regions++; - return (region); -} + instruction = gla2hla(rip, cr3); -void -move_memory_region(struct memory_region *region, uintptr_t start) -{ - size_t len; + error = decode_instruction(instruction, &instr); + if (!error) + error = emulate_decoded_instruction(vm, vcpu, gpa, cr3, + &instr, mr); - len = region->end - region->start; - region->start = start; - region->end = start + len; + return (error); } Modified: projects/bhyve/usr.sbin/bhyve/instruction_emul.h ============================================================================== --- projects/bhyve/usr.sbin/bhyve/instruction_emul.h Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/instruction_emul.h Fri Oct 19 18:11:17 2012 (r241744) @@ -29,19 +29,8 @@ #ifndef _INSTRUCTION_EMUL_H_ #define _INSTRUCTION_EMUL_H_ -struct memory_region; - -typedef int (*emulated_read_func_t)(struct vmctx *vm, int vcpu, uintptr_t addr, - int size, uint64_t *data, void *arg); -typedef int (*emulated_write_func_t)(struct vmctx *vm, int vcpu, uintptr_t addr, - int size, uint64_t data, void *arg); - int emulate_instruction(struct vmctx *vm, int vcpu, uint64_t rip, - uint64_t cr3); -struct memory_region *register_emulated_memory(uintptr_t start, size_t len, - emulated_read_func_t memread, - emulated_write_func_t memwrite, - void *arg); -void move_memory_region(struct memory_region *memory_region, uintptr_t start); + uint64_t cr3, uint64_t gpa, int flags, + struct mem_range *mr); #endif Modified: projects/bhyve/usr.sbin/bhyve/ioapic.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/ioapic.c Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/ioapic.c Fri Oct 19 18:11:17 2012 (r241744) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include "inout.h" +#include "mem.h" #include "instruction_emul.h" #include "fbsdrun.h" @@ -67,10 +68,13 @@ struct ioapic { static struct ioapic ioapics[1]; /* only a single ioapic for now */ -static int ioapic_region_read(struct vmctx *vm, int vcpu, uintptr_t paddr, - int size, uint64_t *data, void *arg); -static int ioapic_region_write(struct vmctx *vm, int vcpu, uintptr_t paddr, - int size, uint64_t data, void *arg); +static int ioapic_region_read(struct ioapic *ioapic, uintptr_t paddr, + int size, uint64_t *data); +static int ioapic_region_write(struct ioapic *ioapic, uintptr_t paddr, + int size, uint64_t data); +static int ioapic_region_handler(struct vmctx *vm, int vcpu, int dir, + uintptr_t paddr, int size, uint64_t *val, + void *arg1, long arg2); static void ioapic_set_pinstate(struct vmctx *ctx, int pin, bool newstate) @@ -139,8 +143,10 @@ ioapic_assert_pin(struct vmctx *ctx, int void ioapic_init(int which) { - int i; + struct mem_range memp; struct ioapic *ioapic; + int error; + int i; assert(which == 0); @@ -153,14 +159,19 @@ ioapic_init(int which) for (i = 0; i < REDIR_ENTRIES; i++) ioapic->redtbl[i] = 0x0001000000010000UL; - /* Register emulated memory region */ ioapic->paddr = IOAPIC_PADDR; - ioapic->region = register_emulated_memory(ioapic->paddr, - sizeof(struct IOAPIC), - ioapic_region_read, - ioapic_region_write, - (void *)(uintptr_t)which); - assert(ioapic->region != NULL); + + /* Register emulated memory region */ + memp.name = "ioapic"; + memp.flags = MEM_F_RW; + memp.handler = ioapic_region_handler; + memp.arg1 = ioapic; + memp.arg2 = which; + memp.base = ioapic->paddr; + memp.size = sizeof(struct IOAPIC); + error = register_mem(&memp); + + assert (error == 0); ioapic->inited = 1; } @@ -237,15 +248,11 @@ ioapic_write(struct ioapic *ioapic, uint } static int -ioapic_region_read(struct vmctx *vm, int vcpu, uintptr_t paddr, int size, - uint64_t *data, void *arg) +ioapic_region_read(struct ioapic *ioapic, uintptr_t paddr, int size, + uint64_t *data) { - int which, offset; - struct ioapic *ioapic; - - which = (uintptr_t)arg; + int offset; - ioapic = &ioapics[which]; offset = paddr - ioapic->paddr; /* @@ -255,7 +262,7 @@ ioapic_region_read(struct vmctx *vm, int if (size != 4 || (offset != IOREGSEL && offset != IOWIN)) { #if 1 printf("invalid access to ioapic%d: size %d, offset %d\n", - which, size, offset); + (int)(ioapic - ioapics), size, offset); #endif *data = 0; return (0); @@ -270,15 +277,11 @@ ioapic_region_read(struct vmctx *vm, int } static int -ioapic_region_write(struct vmctx *vm, int vcpu, uintptr_t paddr, int size, - uint64_t data, void *arg) +ioapic_region_write(struct ioapic *ioapic, uintptr_t paddr, int size, + uint64_t data) { - int which, offset; - struct ioapic *ioapic; - - which = (uintptr_t)arg; + int offset; - ioapic = &ioapics[which]; offset = paddr - ioapic->paddr; /* @@ -288,7 +291,7 @@ ioapic_region_write(struct vmctx *vm, in if (size != 4 || (offset != IOREGSEL && offset != IOWIN)) { #if 1 printf("invalid access to ioapic%d: size %d, offset %d\n", - which, size, offset); + (int)(ioapic - ioapics), size, offset); #endif return (0); } @@ -300,3 +303,23 @@ ioapic_region_write(struct vmctx *vm, in return (0); } + +static int +ioapic_region_handler(struct vmctx *vm, int vcpu, int dir, uintptr_t paddr, + int size, uint64_t *val, void *arg1, long arg2) +{ + struct ioapic *ioapic; + int which; + + ioapic = arg1; + which = arg2; + + assert(ioapic == &ioapics[which]); + + if (dir == MEM_F_READ) + ioapic_region_read(ioapic, paddr, size, val); + else + ioapic_region_write(ioapic, paddr, size, *val); + + return (0); +} Added: projects/bhyve/usr.sbin/bhyve/mem.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/bhyve/usr.sbin/bhyve/mem.c Fri Oct 19 18:11:17 2012 (r241744) @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 2012 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Memory ranges are represented with an RB tree. On insertion, the range + * is checked for overlaps. On lookup, the key has the same base and limit + * so it can be searched within the range. + * + * It is assumed that all setup of ranges takes place in single-threaded + * mode before vCPUs have been started. As such, no locks are used on the + * RB tree. If this is no longer the case, then a r/w lock could be used, + * with readers on the lookup and a writer if the tree needs to be changed + * (and per vCPU caches flushed) + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include + +#include "mem.h" +#include "instruction_emul.h" + +struct mmio_rb_range { + RB_ENTRY(mmio_rb_range) mr_link; /* RB tree links */ + struct mem_range mr_param; + uint64_t mr_base; + uint64_t mr_end; +}; + +struct mmio_rb_tree; +RB_PROTOTYPE(mmio_rb_tree, mmio_rb_range, mr_link, mmio_rb_range_compare); + +RB_HEAD(mmio_rb_tree, mmio_rb_range) mmio_rbroot; + +/* + * Per-vCPU cache. Since most accesses from a vCPU will be to + * consecutive addresses in a range, it makes sense to cache the + * result of a lookup. + */ +static struct mmio_rb_range *mmio_hint[VM_MAXCPU]; + +static int +mmio_rb_range_compare(struct mmio_rb_range *a, struct mmio_rb_range *b) +{ + if (a->mr_end < b->mr_base) + return (-1); + else if (a->mr_base > b->mr_end) + return (1); + return (0); +} + +static int +mmio_rb_lookup(uint64_t addr, struct mmio_rb_range **entry) +{ + struct mmio_rb_range find, *res; + + find.mr_base = find.mr_end = addr; + + res = RB_FIND(mmio_rb_tree, &mmio_rbroot, &find); + + if (res != NULL) { + *entry = res; + return (0); + } + + return (ENOENT); +} + +static int +mmio_rb_add(struct mmio_rb_range *new) +{ + struct mmio_rb_range *overlap; + + overlap = RB_INSERT(mmio_rb_tree, &mmio_rbroot, new); + + if (overlap != NULL) { +#ifdef RB_DEBUG + printf("overlap detected: new %lx:%lx, tree %lx:%lx\n", + new->mr_base, new->mr_end, + overlap->mr_base, overlap->mr_end); +#endif + + return (EEXIST); + } + + return (0); +} + +#if 0 +static void +mmio_rb_dump(void) +{ + struct mmio_rb_range *np; + + RB_FOREACH(np, mmio_rb_tree, &mmio_rbroot) { + printf(" %lx:%lx, %s\n", np->mr_base, np->mr_end, + np->mr_param.name); + } +} +#endif + +RB_GENERATE(mmio_rb_tree, mmio_rb_range, mr_link, mmio_rb_range_compare); + +int +emulate_mem(struct vmctx *ctx, int vcpu, uint64_t paddr, uint64_t rip, + uint64_t cr3, int mode) +{ + struct mmio_rb_range *entry; + int err; + + err = 0; + + /* + * First check the per-vCPU cache + */ + if (mmio_hint[vcpu] && + paddr >= mmio_hint[vcpu]->mr_base && + paddr <= mmio_hint[vcpu]->mr_end) { + err = emulate_instruction(ctx, vcpu, rip, cr3, paddr, mode, + &mmio_hint[vcpu]->mr_param); + } else { + if (mmio_rb_lookup(paddr, &entry)) { + err = ENOENT; + } else { + mmio_hint[vcpu] = entry; + err = emulate_instruction(ctx, vcpu, rip, cr3, paddr, + mode, &entry->mr_param); + } + } + + return (err); +} + +int +register_mem(struct mem_range *memp) +{ + struct mmio_rb_range *mrp; + int err; + + err = 0; + + mrp = malloc(sizeof(struct mmio_rb_range)); + + if (mrp != NULL) { + mrp->mr_param = *memp; + mrp->mr_base = memp->base; + mrp->mr_end = memp->base + memp->size - 1; + + err = mmio_rb_add(mrp); + if (err) + free(mrp); + } else + err = ENOMEM; + + return (err); +} + +void +init_mem(void) +{ + + RB_INIT(&mmio_rbroot); +} Added: projects/bhyve/usr.sbin/bhyve/mem.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/bhyve/usr.sbin/bhyve/mem.h Fri Oct 19 18:11:17 2012 (r241744) @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2012 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MEM_H_ +#define _MEM_H_ + +#include + +struct vmctx; + +typedef int (*mem_func_t)(struct vmctx *ctx, int vcpu, int dir, uint64_t addr, + int size, uint64_t *val, void *arg1, long arg2); + +struct mem_range { + const char *name; + int flags; + mem_func_t handler; + void *arg1; + long arg2; + uint64_t base; + uint64_t size; +}; +#define MEM_F_READ 0x1 +#define MEM_F_WRITE 0x2 +#define MEM_F_RW 0x3 + +void init_mem(void); +int emulate_mem(struct vmctx *, int vcpu, uint64_t paddr, uint64_t rip, + uint64_t cr3, int mode); + +int register_mem(struct mem_range *memp); + +#endif /* _MEM_H_ */ Modified: projects/bhyve/usr.sbin/bhyve/pci_emul.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/pci_emul.c Fri Oct 19 17:45:56 2012 (r241743) +++ projects/bhyve/usr.sbin/bhyve/pci_emul.c Fri Oct 19 18:11:17 2012 (r241744) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include "fbsdrun.h" #include "inout.h" +#include "mem.h" #include "pci_emul.h" #include "ioapic.h" @@ -364,22 +365,26 @@ pci_finish_mptable_names(void) } static int -pci_emul_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, - uint32_t *eax, void *arg) +pci_emul_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) { struct pci_devinst *pdi = arg; struct pci_devemu *pe = pdi->pi_d; - int offset, i; + uint64_t offset; + int i; for (i = 0; i <= PCI_BARMAX; i++) { if (pdi->pi_bar[i].type == PCIBAR_IO && port >= pdi->pi_bar[i].addr && - port + bytes <= pdi->pi_bar[i].addr + pdi->pi_bar[i].size) { + port + bytes <= + pdi->pi_bar[i].addr + pdi->pi_bar[i].size) { offset = port - pdi->pi_bar[i].addr; if (in) - *eax = (*pe->pe_ior)(pdi, i, offset, bytes); + *eax = (*pe->pe_barread)(ctx, vcpu, pdi, i, + offset, bytes); else - (*pe->pe_iow)(pdi, i, offset, bytes, *eax); + (*pe->pe_barwrite)(ctx, vcpu, pdi, i, offset, + bytes, *eax); return (0); } } @@ -387,6 +392,32 @@ pci_emul_handler(struct vmctx *ctx, int } static int +pci_emul_mem_handler(struct vmctx *ctx, int vcpu, int dir, uint64_t addr, + int size, uint64_t *val, void *arg1, long arg2) +{ + struct pci_devinst *pdi = arg1; + struct pci_devemu *pe = pdi->pi_d; + uint64_t offset; + int bidx = (int) arg2; + + assert(bidx <= PCI_BARMAX); + assert(pdi->pi_bar[bidx].type == PCIBAR_MEM32 || + pdi->pi_bar[bidx].type == PCIBAR_MEM64); + assert(addr >= pdi->pi_bar[bidx].addr && + addr + size <= pdi->pi_bar[bidx].addr + pdi->pi_bar[bidx].size); + + offset = addr - pdi->pi_bar[bidx].addr; + + if (dir == MEM_F_WRITE) + (*pe->pe_barwrite)(ctx, vcpu, pdi, bidx, offset, size, *val); + else + *val = (*pe->pe_barread)(ctx, vcpu, pdi, bidx, offset, size); + + return (0); +} *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Fri Oct 19 19:33:13 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 48AB62C8; Fri, 19 Oct 2012 19:33:13 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 0D8308FC0A; Fri, 19 Oct 2012 19:33:13 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 630A0B91C; Fri, 19 Oct 2012 15:33:12 -0400 (EDT) From: John Baldwin To: Andre Oppermann Subject: Re: svn commit: r238907 - projects/calloutng/sys/kern Date: Fri, 19 Oct 2012 15:32:59 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p20; KDE/4.5.5; amd64; ; ) References: <201207301350.q6UDobCI099069@svn.freebsd.org> <201209171113.06861.jhb@freebsd.org> <508119DE.6020106@freebsd.org> In-Reply-To: <508119DE.6020106@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201210191532.59244.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 19 Oct 2012 15:33:12 -0400 (EDT) Cc: Davide Italiano , mlaier@freebsd.org, svn-src-projects@freebsd.org, attilio@freebsd.org, Konstantin Belousov , src-committers@freebsd.org, Stephan Uphoff X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Oct 2012 19:33:13 -0000 On Friday, October 19, 2012 5:14:06 am Andre Oppermann wrote: > On 17.09.2012 17:13, John Baldwin wrote: > > On Monday, September 17, 2012 3:25:44 am Andre Oppermann wrote: > >> Hello Attilio, > >> > >> could you integrate and test this patch from Isilon as well: > >> > >> Add INVARIANT and WITNESS support to rm_lock locks and optimize the > >> synchronization path by replacing a LIST of active readers with a > >> TAILQ. > >> > >> Obtained from: Isilon > >> Submitted by: mlaier > >> > >> http://svn.freebsd.org/changeset/base/234648 > >> > >> You're far deeper into locking than I am. > > > > Some of this is already in the tree, and their WITNESS changes don't quite > > work correctly. I have several fixes (including some of these already) that I > > am just waiting to develop a good test for. Having an _rm_assert() to pull > > from will be good though. > > Any news/progress on this? I need to get some time to test them. www.freebsd.org/~jhb/patches/rmlock.patch is the current set of patches I have. -- John Baldwin From owner-svn-src-projects@FreeBSD.ORG Sat Oct 20 00:28:28 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A3F6BAA9; Sat, 20 Oct 2012 00:28:28 +0000 (UTC) (envelope-from linimon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8B9068FC0A; Sat, 20 Oct 2012 00:28:28 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9K0SS0T009107; Sat, 20 Oct 2012 00:28:28 GMT (envelope-from linimon@svn.freebsd.org) Received: (from linimon@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9K0SSVi009105; Sat, 20 Oct 2012 00:28:28 GMT (envelope-from linimon@svn.freebsd.org) Message-Id: <201210200028.q9K0SSVi009105@svn.freebsd.org> From: Mark Linimon Date: Sat, 20 Oct 2012 00:28:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r241760 - projects/portbuild/qmanager X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2012 00:28:28 -0000 Author: linimon (doc,ports committer) Date: Sat Oct 20 00:28:27 2012 New Revision: 241760 URL: http://svn.freebsd.org/changeset/base/241760 Log: Add the case that is killing us via maxfiles-exceeded. Modified: projects/portbuild/qmanager/retcodes Modified: projects/portbuild/qmanager/retcodes ============================================================================== --- projects/portbuild/qmanager/retcodes Fri Oct 19 23:42:45 2012 (r241759) +++ projects/portbuild/qmanager/retcodes Sat Oct 20 00:28:27 2012 (r241760) @@ -7,6 +7,7 @@ code meaning sent by 253 success: setting up buildid on machine pdispatch 254 error: failed to claim chroot on host/ chroot is empty/ + Failed to scp claim-chroot/ build failed uncleanly pdispatch 255 error: copy failed portbuild 401 error: could not connect qmanagerhandler From owner-svn-src-projects@FreeBSD.ORG Sat Oct 20 01:48:50 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0D387843; Sat, 20 Oct 2012 01:48:50 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E91B38FC0A; Sat, 20 Oct 2012 01:48:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9K1mnhT021114; Sat, 20 Oct 2012 01:48:49 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9K1mng4021110; Sat, 20 Oct 2012 01:48:49 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201210200148.q9K1mng4021110@svn.freebsd.org> From: Rick Macklem Date: Sat, 20 Oct 2012 01:48:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r241761 - in projects/nfsv4.1-client/sys/fs: nfs nfsclient X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2012 01:48:50 -0000 Author: rmacklem Date: Sat Oct 20 01:48:49 2012 New Revision: 241761 URL: http://svn.freebsd.org/changeset/base/241761 Log: The NFSv4 working group has deprecated the offset and length arguments for the NFSv4.1 LayoutCommit operation. As such, only one LayoutCommit is required for all layouts for a file. This allowed the code to be simplified. Modified: projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clstate.c Modified: projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h ============================================================================== --- projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h Sat Oct 20 00:28:27 2012 (r241760) +++ projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h Sat Oct 20 01:48:49 2012 (r241761) @@ -255,6 +255,7 @@ struct nfscllayout { #define NFSLY_RECALLFSID 0x0020 #define NFSLY_RECALLALL 0x0040 #define NFSLY_RETONCLOSE 0x0080 +#define NFSLY_WRITTEN 0x0100 /* Has been used to write to a DS. */ /* * MALLOC'd to the correct length to accommodate the file handle list. @@ -282,7 +283,6 @@ struct nfsclflayout { * Flags for nfsfl_flags. */ #define NFSFL_RECALL 0x0001 /* File layout has been recalled */ -#define NFSFL_WRITTEN 0x0002 /* Has been used to write to a DS. */ /* * Structure that is used to store a LAYOUTRECALL. Modified: projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c ============================================================================== --- projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c Sat Oct 20 00:28:27 2012 (r241760) +++ projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c Sat Oct 20 01:48:49 2012 (r241761) @@ -106,8 +106,8 @@ static int nfsrpc_fillsa(struct nfsmount struct nfsclds **, NFSPROC_T *); static void nfscl_initsessionslots(struct nfsclsession *); static int nfscl_doflayoutio(vnode_t, struct uio *, int *, int *, int *, - nfsv4stateid_t *, int, struct nfscldevinfo *, struct nfsclflayout *, - uint64_t, uint64_t, struct ucred *, NFSPROC_T *); + nfsv4stateid_t *, int, struct nfscldevinfo *, struct nfscllayout *, + struct nfsclflayout *, uint64_t, uint64_t, struct ucred *, NFSPROC_T *); static int nfsrpc_readds(vnode_t, struct uio *, nfsv4stateid_t *, int *, struct nfsclds *, uint64_t, int, struct nfsfh *, struct ucred *, NFSPROC_T *); @@ -5477,7 +5477,7 @@ nfscl_doiods(vnode_t vp, struct uio *uio if (dip != NULL) { error = nfscl_doflayoutio(vp, uiop, iomode, must_commit, &eof, &stateid, rwaccess, dip, - rflp, off, xfer, newcred, p); + layp, rflp, off, xfer, newcred, p); nfscl_reldevinfo(dip); lastbyte = off + xfer - 1; if (error == 0) { @@ -5547,8 +5547,8 @@ nfscl_findlayoutforio(struct nfscllayout static int nfscl_doflayoutio(vnode_t vp, struct uio *uiop, int *iomode, int *must_commit, int *eofp, nfsv4stateid_t *stateidp, int rwflag, struct nfscldevinfo *dp, - struct nfsclflayout *flp, uint64_t off, uint64_t len, struct ucred *cred, - NFSPROC_T *p) + struct nfscllayout *lyp, struct nfsclflayout *flp, uint64_t off, + uint64_t len, struct ucred *cred, NFSPROC_T *p) { uint64_t io_off, rel_off, stripe_unit_size, transfer, xfer; int commit_thru_mds, error = 0, stripe_index, stripe_pos; @@ -5604,7 +5604,7 @@ nfscl_doflayoutio(vnode_t vp, struct uio cred, p); if (error == 0) { NFSLOCKCLSTATE(); - flp->nfsfl_flags |= NFSFL_WRITTEN; + lyp->nfsly_flags |= NFSLY_WRITTEN; NFSUNLOCKCLSTATE(); } } Modified: projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clstate.c ============================================================================== --- projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clstate.c Sat Oct 20 00:28:27 2012 (r241760) +++ projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clstate.c Sat Oct 20 01:48:49 2012 (r241761) @@ -164,7 +164,7 @@ static int nfscl_seq(uint32_t, uint32_t) static void nfscl_layoutreturn(struct nfsmount *, struct nfscllayout *, struct ucred *, NFSPROC_T *); static void nfscl_dolayoutcommit(struct nfsmount *, struct nfscllayout *, - struct nfsclflayout *, struct ucred *, NFSPROC_T *); + struct ucred *, NFSPROC_T *); static short nfscberr_null[] = { 0, @@ -2452,7 +2452,6 @@ nfscl_renewthread(struct nfsclclient *cl struct nfscllockownerfh *lfhp, *nlfhp; struct nfscllockownerfhhead lfh; struct nfscllayout *lyp, *nlyp; - struct nfsclflayout *flp; struct nfscldevinfo *dip, *ndip; struct nfscllayouthead rlh; struct nfsclrecalllayout *recallp; @@ -2651,23 +2650,15 @@ tryagain2: TAILQ_INSERT_HEAD(&rlh, lyp, nfsly_list); /* Handle any layout commits. */ - if (!NFSHASNOLAYOUTCOMMIT(clp->nfsc_nmp)) { - LIST_FOREACH(flp, &lyp->nfsly_flayrw, - nfsfl_list) { - if ((flp->nfsfl_flags & - NFSFL_WRITTEN) != 0) { - flp->nfsfl_flags &= - ~NFSFL_WRITTEN; - NFSUNLOCKCLSTATE(); - NFSCL_DEBUG(3, - "do layoutcommit\n"); - nfscl_dolayoutcommit( - clp->nfsc_nmp, lyp, - flp, cred, p); - NFSLOCKCLSTATE(); - goto tryagain2; - } - } + if (!NFSHASNOLAYOUTCOMMIT(clp->nfsc_nmp) && + (lyp->nfsly_flags & NFSLY_WRITTEN) != 0) { + lyp->nfsly_flags &= ~NFSLY_WRITTEN; + NFSUNLOCKCLSTATE(); + NFSCL_DEBUG(3, "do layoutcommit\n"); + nfscl_dolayoutcommit(clp->nfsc_nmp, lyp, + cred, p); + NFSLOCKCLSTATE(); + goto tryagain2; } } } @@ -5154,17 +5145,12 @@ nfscl_layoutreturn(struct nfsmount *nmp, */ static void nfscl_dolayoutcommit(struct nfsmount *nmp, struct nfscllayout *lyp, - struct nfsclflayout *flp, struct ucred *cred, NFSPROC_T *p) + struct ucred *cred, NFSPROC_T *p) { - uint64_t len; int error; - if (flp->nfsfl_end == UINT64_MAX) - len = UINT64_MAX; - else - len = flp->nfsfl_end - flp->nfsfl_off; error = nfsrpc_layoutcommit(nmp, lyp->nfsly_fh, lyp->nfsly_fhlen, - 0, flp->nfsfl_off, len, lyp->nfsly_lastbyte, &lyp->nfsly_stateid, + 0, 0, 0, lyp->nfsly_lastbyte, &lyp->nfsly_stateid, NFSLAYOUT_NFSV4_1_FILES, 0, NULL, cred, p, NULL); if (error == NFSERR_NOTSUPP) { /* If the server doesn't want it, don't bother doing it. */ @@ -5182,7 +5168,6 @@ nfscl_layoutcommit(vnode_t vp, NFSPROC_T { struct nfsclclient *clp; struct nfscllayout *lyp; - struct nfsclflayout *flp; struct nfsnode *np = VTONFS(vp); mount_t mp; struct nfsmount *nmp; @@ -5208,16 +5193,13 @@ nfscl_layoutcommit(vnode_t vp, NFSPROC_T return (EPERM); } tryagain: - LIST_FOREACH(flp, &lyp->nfsly_flayrw, nfsfl_list) { - if ((flp->nfsfl_flags & NFSFL_WRITTEN) != 0) { - flp->nfsfl_flags &= ~NFSFL_WRITTEN; - NFSUNLOCKCLSTATE(); - NFSCL_DEBUG(4, "do layoutcommit2\n"); - nfscl_dolayoutcommit(clp->nfsc_nmp, lyp, flp, - NFSPROCCRED(p), p); - NFSLOCKCLSTATE(); - goto tryagain; - } + if ((lyp->nfsly_flags & NFSLY_WRITTEN) != 0) { + lyp->nfsly_flags &= ~NFSLY_WRITTEN; + NFSUNLOCKCLSTATE(); + NFSCL_DEBUG(4, "do layoutcommit2\n"); + nfscl_dolayoutcommit(clp->nfsc_nmp, lyp, NFSPROCCRED(p), p); + NFSLOCKCLSTATE(); + goto tryagain; } nfsv4_relref(&lyp->nfsly_lock); NFSUNLOCKCLSTATE(); From owner-svn-src-projects@FreeBSD.ORG Sat Oct 20 08:23:05 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C24E2DBC; Sat, 20 Oct 2012 08:23:05 +0000 (UTC) (envelope-from neel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A8E738FC14; Sat, 20 Oct 2012 08:23:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9K8N55A086057; Sat, 20 Oct 2012 08:23:05 GMT (envelope-from neel@svn.freebsd.org) Received: (from neel@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9K8N5Bi086051; Sat, 20 Oct 2012 08:23:05 GMT (envelope-from neel@svn.freebsd.org) Message-Id: <201210200823.q9K8N5Bi086051@svn.freebsd.org> From: Neel Natu Date: Sat, 20 Oct 2012 08:23:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r241766 - in projects/bhyve/sys/amd64/vmm: . io X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2012 08:23:05 -0000 Author: neel Date: Sat Oct 20 08:23:05 2012 New Revision: 241766 URL: http://svn.freebsd.org/changeset/base/241766 Log: Calculate the number of host ticks until the next guest timer interrupt. This information will be used in conjunction with guest "HLT exiting" to yield the thread hosting the virtual cpu. Obtained from: NetApp Modified: projects/bhyve/sys/amd64/vmm/io/vlapic.c projects/bhyve/sys/amd64/vmm/io/vlapic.h projects/bhyve/sys/amd64/vmm/vmm_lapic.c projects/bhyve/sys/amd64/vmm/vmm_lapic.h Modified: projects/bhyve/sys/amd64/vmm/io/vlapic.c ============================================================================== --- projects/bhyve/sys/amd64/vmm/io/vlapic.c Sat Oct 20 08:06:31 2012 (r241765) +++ projects/bhyve/sys/amd64/vmm/io/vlapic.c Sat Oct 20 08:23:05 2012 (r241766) @@ -121,6 +121,31 @@ struct vlapic { enum boot_state boot_state; }; +#define VLAPIC_BUS_FREQ tsc_freq + +static int +vlapic_timer_divisor(uint32_t dcr) +{ + switch (dcr & 0xB) { + case APIC_TDCR_2: + return (2); + case APIC_TDCR_4: + return (4); + case APIC_TDCR_8: + return (8); + case APIC_TDCR_16: + return (16); + case APIC_TDCR_32: + return (32); + case APIC_TDCR_64: + return (64); + case APIC_TDCR_128: + return (128); + default: + panic("vlapic_timer_divisor: invalid dcr 0x%08x", dcr); + } +} + static void vlapic_mask_lvts(uint32_t *lvts, int num_lvt) { @@ -175,6 +200,7 @@ vlapic_op_reset(void* dev) memset(lapic, 0, sizeof(*lapic)); lapic->apr = vlapic->vcpuid; vlapic_init_ipi(vlapic); + vlapic->divisor = vlapic_timer_divisor(lapic->dcr_timer); if (vlapic->vcpuid == 0) vlapic->boot_state = BS_RUNNING; /* BSP */ @@ -218,32 +244,6 @@ vlapic_set_intr_ready(struct vlapic *vla VLAPIC_CTR_IRR(vlapic, "vlapic_set_intr_ready"); } -#define VLAPIC_BUS_FREQ tsc_freq -#define VLAPIC_DCR(x) ((x->dcr_timer & 0x8) >> 1)|(x->dcr_timer & 0x3) - -static int -vlapic_timer_divisor(uint32_t dcr) -{ - switch (dcr & 0xB) { - case APIC_TDCR_2: - return (2); - case APIC_TDCR_4: - return (4); - case APIC_TDCR_8: - return (8); - case APIC_TDCR_16: - return (16); - case APIC_TDCR_32: - return (32); - case APIC_TDCR_64: - return (64); - case APIC_TDCR_128: - return (128); - default: - panic("vlapic_timer_divisor: invalid dcr 0x%08x", dcr); - } -} - static void vlapic_start_timer(struct vlapic *vlapic, uint32_t elapsed) { @@ -755,59 +755,68 @@ vlapic_op_mem_write(void* dev, uint64_t return (retval); } -void +int vlapic_timer_tick(struct vlapic *vlapic) { - int curticks, delta, periodic; + int curticks, delta, periodic, fired; uint32_t ccr; - uint32_t decrement, remainder; + uint32_t decrement, leftover; +restart: curticks = ticks; - - /* Common case */ delta = curticks - vlapic->ccr_ticks; - if (delta == 0) - return; /* Local APIC timer is disabled */ if (vlapic->apic.icr_timer == 0) - return; + return (-1); /* One-shot mode and timer has already counted down to zero */ periodic = vlapic_periodic_timer(vlapic); if (!periodic && vlapic->apic.ccr_timer == 0) - return; + return (-1); /* * The 'curticks' and 'ccr_ticks' are out of sync by more than * 2^31 ticks. We deal with this by restarting the timer. */ if (delta < 0) { vlapic_start_timer(vlapic, 0); - return; + goto restart; } - ccr = vlapic->apic.ccr_timer; + fired = 0; decrement = (VLAPIC_BUS_FREQ / vlapic->divisor) / hz; + + vlapic->ccr_ticks = curticks; + ccr = vlapic->apic.ccr_timer; + while (delta-- > 0) { - if (ccr <= decrement) { - remainder = decrement - ccr; - vlapic_fire_timer(vlapic); - if (periodic) { - vlapic_start_timer(vlapic, remainder); - ccr = vlapic->apic.ccr_timer; - } else { - /* - * One-shot timer has counted down to zero. - */ - ccr = 0; - break; - } - } else + if (ccr > decrement) { ccr -= decrement; + continue; + } + + /* Trigger the local apic timer interrupt */ + vlapic_fire_timer(vlapic); + if (periodic) { + leftover = decrement - ccr; + vlapic_start_timer(vlapic, leftover); + ccr = vlapic->apic.ccr_timer; + } else { + /* + * One-shot timer has counted down to zero. + */ + ccr = 0; + } + fired = 1; + break; } - vlapic->ccr_ticks = curticks; vlapic->apic.ccr_timer = ccr; + + if (!fired) + return ((ccr / decrement) + 1); + else + return (0); } struct vdev_ops vlapic_dev_ops = { Modified: projects/bhyve/sys/amd64/vmm/io/vlapic.h ============================================================================== --- projects/bhyve/sys/amd64/vmm/io/vlapic.h Sat Oct 20 08:06:31 2012 (r241765) +++ projects/bhyve/sys/amd64/vmm/io/vlapic.h Sat Oct 20 08:23:05 2012 (r241766) @@ -102,7 +102,7 @@ int vlapic_op_mem_read(void* dev, uint64 int vlapic_pending_intr(struct vlapic *vlapic); void vlapic_intr_accepted(struct vlapic *vlapic, int vector); void vlapic_set_intr_ready(struct vlapic *vlapic, int vector); -void vlapic_timer_tick(struct vlapic *vlapic); +int vlapic_timer_tick(struct vlapic *vlapic); uint64_t vlapic_get_apicbase(struct vlapic *vlapic); void vlapic_set_apicbase(struct vlapic *vlapic, uint64_t val); Modified: projects/bhyve/sys/amd64/vmm/vmm_lapic.c ============================================================================== --- projects/bhyve/sys/amd64/vmm/vmm_lapic.c Sat Oct 20 08:06:31 2012 (r241765) +++ projects/bhyve/sys/amd64/vmm/vmm_lapic.c Sat Oct 20 08:23:05 2012 (r241766) @@ -106,14 +106,14 @@ lapic_set_intr(struct vm *vm, int cpu, i return (0); } -void +int lapic_timer_tick(struct vm *vm, int cpu) { struct vlapic *vlapic; vlapic = vm_lapic(vm, cpu); - vlapic_timer_tick(vlapic); + return (vlapic_timer_tick(vlapic)); } static boolean_t Modified: projects/bhyve/sys/amd64/vmm/vmm_lapic.h ============================================================================== --- projects/bhyve/sys/amd64/vmm/vmm_lapic.h Sat Oct 20 08:06:31 2012 (r241765) +++ projects/bhyve/sys/amd64/vmm/vmm_lapic.h Sat Oct 20 08:23:05 2012 (r241766) @@ -38,7 +38,7 @@ int lapic_wrmsr(struct vm *vm, int cpu, int lapic_mmio(struct vm *vm, int cpu, u_int offset, int rd, struct vie *); -void lapic_timer_tick(struct vm *vm, int cpu); +int lapic_timer_tick(struct vm *vm, int cpu); /* * Returns a vector between 32 and 255 if an interrupt is pending in the From owner-svn-src-projects@FreeBSD.ORG Sat Oct 20 14:21:24 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C7E94EF3; Sat, 20 Oct 2012 14:21:24 +0000 (UTC) (envelope-from gavin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 978948FC08; Sat, 20 Oct 2012 14:21:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9KELO4N044554; Sat, 20 Oct 2012 14:21:24 GMT (envelope-from gavin@svn.freebsd.org) Received: (from gavin@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9KELOKi044553; Sat, 20 Oct 2012 14:21:24 GMT (envelope-from gavin@svn.freebsd.org) Message-Id: <201210201421.q9KELOKi044553@svn.freebsd.org> From: Gavin Atkinson Date: Sat, 20 Oct 2012 14:21:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r241782 - projects/pciehp X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2012 14:21:24 -0000 Author: gavin Date: Sat Oct 20 14:21:24 2012 New Revision: 241782 URL: http://svn.freebsd.org/changeset/base/241782 Log: Create a branch to experiment with PCIe HotPlug support. I plan to experiment with support for PCIe HotPlug, primarily on laptops with ExpressCard slots although hopefully extending to server chassis with complete PCIe HP hardware (e.g. indicator LEDs, attention buttons and indicators, etc) as and when I can obtain such hardware. I welcome others to become involved with this, feel free to contact me. Added: - copied from r241781, head/ Directory Properties: projects/pciehp/ (props changed)