From owner-svn-src-stable-6@FreeBSD.ORG Mon Mar 15 18:33:33 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 14E2F106566B; Mon, 15 Mar 2010 18:33:33 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 029F78FC19; Mon, 15 Mar 2010 18:33:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2FIXW2U042533; Mon, 15 Mar 2010 18:33:32 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2FIXWf4042530; Mon, 15 Mar 2010 18:33:32 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201003151833.o2FIXWf4042530@svn.freebsd.org> From: Marius Strobl Date: Mon, 15 Mar 2010 18:33:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205185 - stable/6/lib/libc/sparc64/fpu X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2010 18:33:33 -0000 Author: marius Date: Mon Mar 15 18:33:32 2010 New Revision: 205185 URL: http://svn.freebsd.org/changeset/base/205185 Log: MFC: r204974, r205002 - The OPSZ macro actually only does the right thing for int32 and int64 operands but not for double and extended double ones. Instead of trying to fix the macro just nuke it and unroll the loops in the correct way though as extended double operands turn out to be the only special case. - For FxTO{s,d,q} the source operand is int64 so rs2 has to be re-decoded after setting type accordingly as it's generally decoded using the low 2 bits as the type, which are 0 for these three instructions. - Similarly, in case of F{s,d,q}TOx the target is int64 so rd has to be re-decoded using not only the operand mask appropriate for int64 but also the correct register number encoding. - Use const where appropriate. - Wrap long lines. Submitted by: Peter Jeremy (partly) Modified: stable/6/lib/libc/sparc64/fpu/fpu.c stable/6/lib/libc/sparc64/fpu/fpu_emu.h Directory Properties: stable/6/lib/libc/ (props changed) Modified: stable/6/lib/libc/sparc64/fpu/fpu.c ============================================================================== --- stable/6/lib/libc/sparc64/fpu/fpu.c Mon Mar 15 18:33:23 2010 (r205184) +++ stable/6/lib/libc/sparc64/fpu/fpu.c Mon Mar 15 18:33:32 2010 (r205185) @@ -101,7 +101,7 @@ __FBSDID("$FreeBSD$"); #define X8(x) X4(x),X4(x) #define X16(x) X8(x),X8(x) -static char cx_to_trapx[] = { +static const char cx_to_trapx[] = { X1(FSR_NX), X2(FSR_DZ), X4(FSR_UF), @@ -117,7 +117,8 @@ int __fpe_debug = 0; #endif #endif /* FPU_DEBUG */ -static int __fpu_execute(struct utrapframe *, struct fpemu *, u_int32_t, u_long); +static int __fpu_execute(struct utrapframe *, struct fpemu *, u_int32_t, + u_long); /* * Need to use an fpstate on the stack; we could switch, so we cannot safely @@ -173,7 +174,7 @@ __fpu_exception(struct utrapframe *uf) void __fpu_dumpfpn(struct fpn *fp) { - static char *class[] = { + static const char *const class[] = { "SNAN", "QNAN", "ZERO", "NUM", "INF" }; @@ -185,15 +186,11 @@ __fpu_dumpfpn(struct fpn *fp) } #endif -static int opmask[] = {0, 0, 1, 3}; +static const int opmask[] = {0, 0, 1, 3, 1}; /* Decode 5 bit register field depending on the type. */ #define RN_DECODE(tp, rn) \ - ((tp == FTYPE_DBL || tp == FTYPE_EXT ? INSFPdq_RN((rn)) : (rn)) & \ - ~opmask[tp]) - -/* Operand size in 32-bit registers. */ -#define OPSZ(tp) ((tp) == FTYPE_LNG ? 2 : (1 << (tp))) + ((tp) >= FTYPE_DBL ? INSFPdq_RN(rn) & ~opmask[tp] : (rn)) /* * Helper for forming the below case statements. Build only the op3 and opf @@ -213,8 +210,6 @@ static void __fpu_mov(struct fpemu *fe, int type, int rd, int rs2, u_int32_t nand, u_int32_t xor) { - u_int64_t tmp64; - int i; if (type == FTYPE_INT || type == FTYPE_SNG) __fpu_setreg(rd, (__fpu_getreg(rs2) & ~nand) ^ xor); @@ -223,13 +218,10 @@ __fpu_mov(struct fpemu *fe, int type, in * Need to use the double versions to be able to access * the upper 32 fp registers. */ - for (i = 0; i < OPSZ(type); i += 2, rd += 2, rs2 += 2) { - tmp64 = __fpu_getreg64(rs2); - if (i == 0) - tmp64 = (tmp64 & ~((u_int64_t)nand << 32)) ^ - ((u_int64_t)xor << 32); - __fpu_setreg64(rd, tmp64); - } + __fpu_setreg64(rd, (__fpu_getreg64(rs2) & + ~((u_int64_t)nand << 32)) ^ ((u_int64_t)xor << 32)); + if (type == FTYPE_EXT) + __fpu_setreg64(rd + 2, __fpu_getreg64(rs2 + 2)); } } @@ -275,17 +267,17 @@ __fpu_cmpck(struct fpemu *fe) * multiply two integers this way. */ static int -__fpu_execute(struct utrapframe *uf, struct fpemu *fe, u_int32_t insn, u_long tstate) +__fpu_execute(struct utrapframe *uf, struct fpemu *fe, u_int32_t insn, + u_long tstate) { struct fpn *fp; int opf, rs1, rs2, rd, type, mask, cx, cond; u_long reg, fsr; u_int space[4]; - int i; /* * `Decode' and execute instruction. Start with no exceptions. - * The type of any opf opcode is in the bottom two bits, so we + * The type of almost any OPF opcode is in the bottom two bits, so we * squish them out here. */ opf = insn & (IF_MASK(IF_F3_OP3_SHIFT, IF_F3_OP3_BITS) | @@ -363,7 +355,7 @@ __fpu_execute(struct utrapframe *uf, str __fpu_explode(fe, &fe->fe_f2, type, rs2); __fpu_compare(fe, 1, IF_F3_CC(insn)); return (__fpu_cmpck(fe)); - case FOP(INS2_FPop1, INSFP1_FMOV): /* these should all be pretty obvious */ + case FOP(INS2_FPop1, INSFP1_FMOV): __fpu_mov(fe, type, rd, rs2, 0, 0); return (0); case FOP(INS2_FPop1, INSFP1_FNEG): @@ -414,6 +406,7 @@ __fpu_execute(struct utrapframe *uf, str case FOP(INS2_FPop1, INSFP1_FxTOd): case FOP(INS2_FPop1, INSFP1_FxTOq): type = FTYPE_LNG; + rs2 = RN_DECODE(type, IF_F3_RS2(insn)); __fpu_explode(fe, fp = &fe->fe_f1, type, rs2); /* sneaky; depends on instruction encoding */ type = (IF_F3_OPF(insn) >> 2) & 3; @@ -422,8 +415,7 @@ __fpu_execute(struct utrapframe *uf, str case FOP(INS2_FPop1, INSFP1_FTOx): __fpu_explode(fe, fp = &fe->fe_f1, type, rs2); type = FTYPE_LNG; - mask = 1; /* needs 2 registers */ - rd = IF_F3_RD(insn) & ~mask; + rd = RN_DECODE(type, IF_F3_RD(insn)); break; case FOP(INS2_FPop1, INSFP1_FTOs): case FOP(INS2_FPop1, INSFP1_FTOd): @@ -461,10 +453,10 @@ __fpu_execute(struct utrapframe *uf, str if (type == FTYPE_INT || type == FTYPE_SNG) __fpu_setreg(rd, space[0]); else { - for (i = 0; i < OPSZ(type); i += 2) { - __fpu_setreg64(rd + i, ((u_int64_t)space[i] << 32) | - space[i + 1]); - } + __fpu_setreg64(rd, ((u_int64_t)space[0] << 32) | space[1]); + if (type == FTYPE_EXT) + __fpu_setreg64(rd + 2, + ((u_int64_t)space[2] << 32) | space[3]); } return (0); /* success */ } Modified: stable/6/lib/libc/sparc64/fpu/fpu_emu.h ============================================================================== --- stable/6/lib/libc/sparc64/fpu/fpu_emu.h Mon Mar 15 18:33:23 2010 (r205184) +++ stable/6/lib/libc/sparc64/fpu/fpu_emu.h Mon Mar 15 18:33:32 2010 (r205185) @@ -149,7 +149,7 @@ struct fpn { #define FTYPE_SNG INSFP_s #define FTYPE_DBL INSFP_d #define FTYPE_EXT INSFP_q -#define FTYPE_LNG -1 +#define FTYPE_LNG 4 /* * Emulator state. From owner-svn-src-stable-6@FreeBSD.ORG Mon Mar 15 19:04:56 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C1D84106564A; Mon, 15 Mar 2010 19:04:56 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A60A18FC17; Mon, 15 Mar 2010 19:04:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2FJ4uDo049657; Mon, 15 Mar 2010 19:04:56 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2FJ4uT3049654; Mon, 15 Mar 2010 19:04:56 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201003151904.o2FJ4uT3049654@svn.freebsd.org> From: Marius Strobl Date: Mon, 15 Mar 2010 19:04:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205188 - stable/6/sys/dev/mii X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2010 19:04:57 -0000 Author: marius Date: Mon Mar 15 19:04:56 2010 New Revision: 205188 URL: http://svn.freebsd.org/changeset/base/205188 Log: MFC: r204144 Add support for BCM54K2 found in combination with Apple K2 GMAC. Submitted by: Andreas Tobler Obtained from: OpenBSD Modified: stable/6/sys/dev/mii/brgphy.c stable/6/sys/dev/mii/miidevs Directory Properties: stable/6/sys/ (props changed) stable/6/sys/contrib/pf/ (props changed) stable/6/sys/dev/cxgb/ (props changed) Modified: stable/6/sys/dev/mii/brgphy.c ============================================================================== --- stable/6/sys/dev/mii/brgphy.c Mon Mar 15 19:04:51 2010 (r205187) +++ stable/6/sys/dev/mii/brgphy.c Mon Mar 15 19:04:56 2010 (r205188) @@ -104,6 +104,7 @@ static void brgphy_reset(struct mii_soft static void brgphy_enable_loopback(struct mii_softc *); static void bcm5401_load_dspcode(struct mii_softc *); static void bcm5411_load_dspcode(struct mii_softc *); +static void bcm54k2_load_dspcode(struct mii_softc *); static void brgphy_fixup_5704_a0_bug(struct mii_softc *); static void brgphy_fixup_adc_bug(struct mii_softc *); static void brgphy_fixup_adjust_trim(struct mii_softc *); @@ -117,6 +118,7 @@ static const struct mii_phydesc brgphys[ MII_PHY_DESC(xxBROADCOM, BCM5400), MII_PHY_DESC(xxBROADCOM, BCM5401), MII_PHY_DESC(xxBROADCOM, BCM5411), + MII_PHY_DESC(xxBROADCOM, BCM54K2), MII_PHY_DESC(xxBROADCOM, BCM5701), MII_PHY_DESC(xxBROADCOM, BCM5703), MII_PHY_DESC(xxBROADCOM, BCM5704), @@ -418,6 +420,9 @@ brgphy_service(struct mii_softc *sc, str case MII_MODEL_xxBROADCOM_BCM5411: bcm5411_load_dspcode(sc); break; + case MII_MODEL_xxBROADCOM_BCM54K2: + bcm54k2_load_dspcode(sc); + break; } break; case MII_OUI_xxBROADCOM_ALT1: @@ -717,6 +722,24 @@ bcm5411_load_dspcode(struct mii_softc *s PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); } +void +bcm54k2_load_dspcode(struct mii_softc *sc) +{ + static const struct { + int reg; + uint16_t val; + } dspcode[] = { + { 4, 0x01e1 }, + { 9, 0x0300 }, + { 0, 0 }, + }; + int i; + + for (i = 0; dspcode[i].reg != 0; i++) + PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); + +} + static void brgphy_fixup_5704_a0_bug(struct mii_softc *sc) { @@ -917,6 +940,9 @@ brgphy_reset(struct mii_softc *sc) case MII_MODEL_xxBROADCOM_BCM5411: bcm5411_load_dspcode(sc); break; + case MII_MODEL_xxBROADCOM_BCM54K2: + bcm54k2_load_dspcode(sc); + break; } break; case MII_OUI_xxBROADCOM_ALT1: Modified: stable/6/sys/dev/mii/miidevs ============================================================================== --- stable/6/sys/dev/mii/miidevs Mon Mar 15 19:04:51 2010 (r205187) +++ stable/6/sys/dev/mii/miidevs Mon Mar 15 19:04:56 2010 (r205188) @@ -131,6 +131,7 @@ model xxBROADCOM BCM5703 0x0016 BCM5703 model xxBROADCOM BCM5704 0x0019 BCM5704 10/100/1000baseTX PHY model xxBROADCOM BCM5705 0x001a BCM5705 10/100/1000baseTX PHY model xxBROADCOM BCM5750 0x0018 BCM5750 10/100/1000baseTX PHY +model xxBROADCOM BCM54K2 0x002e BCM54K2 10/100/1000baseTX PHY model xxBROADCOM BCM5714 0x0034 BCM5714 10/100/1000baseTX PHY model xxBROADCOM BCM5780 0x0035 BCM5780 10/100/1000baseTX PHY model xxBROADCOM BCM5708C 0x0036 BCM5708C 10/100/1000baseTX PHY From owner-svn-src-stable-6@FreeBSD.ORG Mon Mar 15 19:13:53 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 348E6106566C; Mon, 15 Mar 2010 19:13:53 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 23C4F8FC08; Mon, 15 Mar 2010 19:13:53 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2FJDrmM051817; Mon, 15 Mar 2010 19:13:53 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2FJDr3L051815; Mon, 15 Mar 2010 19:13:53 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201003151913.o2FJDr3L051815@svn.freebsd.org> From: Marius Strobl Date: Mon, 15 Mar 2010 19:13:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205191 - stable/6/sys/dev/gem X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2010 19:13:53 -0000 Author: marius Date: Mon Mar 15 19:13:52 2010 New Revision: 205191 URL: http://svn.freebsd.org/changeset/base/205191 Log: MFC: r204222 According to the Linux sungem driver, in case of Apple (K2) GMACs GEM_MIF_CONFIG_MDI0 cannot be trusted when the firmware has powered down the chip so the internal transceiver has to be hardcoded. This is also in line with the AppleGMACEthernet driver, which just doesn't distinguish between internal/external transceiver and MDIO/MDI1 respectively in the first place. Tested by: Andreas Tobler Modified: stable/6/sys/dev/gem/if_gem.c Directory Properties: stable/6/sys/ (props changed) stable/6/sys/contrib/pf/ (props changed) stable/6/sys/dev/cxgb/ (props changed) Modified: stable/6/sys/dev/gem/if_gem.c ============================================================================== --- stable/6/sys/dev/gem/if_gem.c Mon Mar 15 19:13:49 2010 (r205190) +++ stable/6/sys/dev/gem/if_gem.c Mon Mar 15 19:13:52 2010 (r205191) @@ -298,8 +298,11 @@ gem_attach(struct gem_softc *sc) /* * Fall back on an internal PHY if no external PHY was found. + * Note that with Apple (K2) GMACs GEM_MIF_CONFIG_MDI0 can't be + * trusted when the firmware has powered down the chip. */ - if (error != 0 && (v & GEM_MIF_CONFIG_MDI0) != 0) { + if (error != 0 && + ((v & GEM_MIF_CONFIG_MDI0) != 0 || GEM_IS_APPLE(sc))) { v &= ~GEM_MIF_CONFIG_PHY_SEL; GEM_BANK1_WRITE_4(sc, GEM_MIF_CONFIG, v); switch (sc->sc_variant) { From owner-svn-src-stable-6@FreeBSD.ORG Wed Mar 17 20:32:14 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3999D106566C; Wed, 17 Mar 2010 20:32:14 +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 1D5508FC18; Wed, 17 Mar 2010 20:32:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2HKWE2R009461; Wed, 17 Mar 2010 20:32:14 GMT (envelope-from gavin@svn.freebsd.org) Received: (from gavin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2HKWDbL009459; Wed, 17 Mar 2010 20:32:13 GMT (envelope-from gavin@svn.freebsd.org) Message-Id: <201003172032.o2HKWDbL009459@svn.freebsd.org> From: Gavin Atkinson Date: Wed, 17 Mar 2010 20:32:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205261 - stable/6/sbin/growfs X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Mar 2010 20:32:14 -0000 Author: gavin Date: Wed Mar 17 20:32:13 2010 New Revision: 205261 URL: http://svn.freebsd.org/changeset/base/205261 Log: Merge r201401 from head: Remove dead code. This section of code is only run in the (sblock.fs_magic == FS_UFS1_MAGIC) case, so the check within the loop is redundant. Merge 203835 from head: When growing a UFS1 filesystem, we need to initialise all inodes in any new cylinder groups that are created. When the filesystem is first created, newfs always initialises the first two blocks of inodes, and then in the UFS1 case will also initialise the remaining inode blocks. The changes in growfs.c 1.23 broke the initialisation of all inodes, seemingly based on this implementation detail in newfs(8). The result was that instead of initialising all inodes, we would actually end up initialising all but the first two blocks of inodes. If the filesystem was grown into empty (all-zeros) space then the resulting filesystem was fine, however when grown onto non-zeroed space the filesystem produced would appear to have massive corruption on the first fsck after growing. A test case for this problem can be found in the PR audit trail. Fix this by once again initialising all inodes in the UFS1 case. PR: bin/115174 Submitted by: "Nate Eldredge" Reviewed by: mjacob Modified: stable/6/sbin/growfs/growfs.c Directory Properties: stable/6/sbin/growfs/ (props changed) Modified: stable/6/sbin/growfs/growfs.c ============================================================================== --- stable/6/sbin/growfs/growfs.c Wed Mar 17 20:30:37 2010 (r205260) +++ stable/6/sbin/growfs/growfs.c Wed Mar 17 20:32:13 2010 (r205261) @@ -376,7 +376,6 @@ initcg(int cylno, time_t utime, int fso, long d, dlower, dupper, blkno, start; ufs2_daddr_t i, cbase, dmax; struct ufs1_dinode *dp1; - struct ufs2_dinode *dp2; struct csum *cs; if (iobuf == NULL && (iobuf = malloc(sblock.fs_bsize)) == NULL) { @@ -446,25 +445,18 @@ initcg(int cylno, time_t utime, int fso, acg.cg_cs.cs_nifree--; } /* - * XXX Newfs writes out two blocks of initialized inodes - * unconditionally. Should we check here to make sure that they - * were actually written? + * For the old file system, we have to initialize all the inodes. */ if (sblock.fs_magic == FS_UFS1_MAGIC) { bzero(iobuf, sblock.fs_bsize); - for (i = 2 * sblock.fs_frag; i < sblock.fs_ipg / INOPF(&sblock); + for (i = 0; i < sblock.fs_ipg / INOPF(&sblock); i += sblock.fs_frag) { dp1 = (struct ufs1_dinode *)iobuf; - dp2 = (struct ufs2_dinode *)iobuf; #ifdef FSIRAND - for (j = 0; j < INOPB(&sblock); j++) - if (sblock.fs_magic == FS_UFS1_MAGIC) { - dp1->di_gen = random(); - dp1++; - } else { - dp2->di_gen = random(); - dp2++; - } + for (j = 0; j < INOPB(&sblock); j++) { + dp1->di_gen = random(); + dp1++; + } #endif wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i), sblock.fs_bsize, iobuf, fso, Nflag); From owner-svn-src-stable-6@FreeBSD.ORG Fri Mar 19 12:07:29 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1648B106567E; Fri, 19 Mar 2010 12:07:29 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 048998FC0A; Fri, 19 Mar 2010 12:07:29 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2JC7SOr042582; Fri, 19 Mar 2010 12:07:28 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2JC7SUI042580; Fri, 19 Mar 2010 12:07:28 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201003191207.o2JC7SUI042580@svn.freebsd.org> From: Jaakko Heinonen Date: Fri, 19 Mar 2010 12:07:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205331 - stable/6/lib/libc/stdio X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2010 12:07:29 -0000 Author: jh Date: Fri Mar 19 12:07:28 2010 New Revision: 205331 URL: http://svn.freebsd.org/changeset/base/205331 Log: MFC r204447: In _gettemp(), check that the length of the path doesn't exceed MAXPATHLEN. Otherwise the path name (or part of it) may not fit to carrybuf causing a buffer overflow. PR: bin/140228 Modified: stable/6/lib/libc/stdio/mktemp.c Directory Properties: stable/6/lib/libc/ (props changed) Modified: stable/6/lib/libc/stdio/mktemp.c ============================================================================== --- stable/6/lib/libc/stdio/mktemp.c Fri Mar 19 12:04:56 2010 (r205330) +++ stable/6/lib/libc/stdio/mktemp.c Fri Mar 19 12:07:28 2010 (r205331) @@ -120,6 +120,10 @@ _gettemp(path, doopen, domkdir, slen) for (trv = path; *trv != '\0'; ++trv) ; + if (trv - path >= MAXPATHLEN) { + errno = ENAMETOOLONG; + return (0); + } trv -= slen; suffp = trv; --trv; From owner-svn-src-stable-6@FreeBSD.ORG Fri Mar 19 22:39:27 2010 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB909106566B; Fri, 19 Mar 2010 22:39:27 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C8B2F8FC0A; Fri, 19 Mar 2010 22:39:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2JMdRsU085364; Fri, 19 Mar 2010 22:39:27 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2JMdRQs085360; Fri, 19 Mar 2010 22:39:27 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201003192239.o2JMdRQs085360@svn.freebsd.org> From: Attilio Rao Date: Fri, 19 Mar 2010 22:39:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205349 - stable/6/sys/vm X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2010 22:39:28 -0000 Author: attilio Date: Fri Mar 19 22:39:27 2010 New Revision: 205349 URL: http://svn.freebsd.org/changeset/base/205349 Log: MFC 181019, 183474, 191277, and 191626: - Move the code for doing out-of-memory grass from vm_pageout_scan() into the separate function vm_pageout_oom(). Supply a parameter for vm_pageout_oom() describing a reason for the call. - Call vm_pageout_oom() from the swp_pager_meta_build() when swap zone is exhausted. - In both pageout oom handler and vm_daemon, acquire the reference to the vmspace of the examined process instead of directly accessing its vmspace, that may change. Also, as an optimization, check for P_INEXEC flag before examining the process. Sponsored by: Sandvine Incorporated Reviewed by: emaste Modified: stable/6/sys/vm/swap_pager.c stable/6/sys/vm/vm_pageout.c stable/6/sys/vm/vm_pageout.h Directory Properties: stable/6/sys/ (props changed) stable/6/sys/contrib/pf/ (props changed) stable/6/sys/dev/cxgb/ (props changed) Modified: stable/6/sys/vm/swap_pager.c ============================================================================== --- stable/6/sys/vm/swap_pager.c Fri Mar 19 21:29:30 2010 (r205348) +++ stable/6/sys/vm/swap_pager.c Fri Mar 19 22:39:27 2010 (r205349) @@ -1680,7 +1680,7 @@ swp_pager_meta_build(vm_object_t object, { struct swblock *swap; struct swblock **pswap; - int idx; + int dummy, idx; VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); /* @@ -1720,9 +1720,12 @@ retry: if (swap == NULL) { mtx_unlock(&swhash_mtx); VM_OBJECT_UNLOCK(object); - if (uma_zone_exhausted(swap_zone)) + if (uma_zone_exhausted(swap_zone)) { printf("swap zone exhausted, increase kern.maxswzone\n"); - VM_WAIT; + vm_pageout_oom(VM_OOM_SWAPZ); + tsleep(&dummy, PVM, "swzonex", 10); + } else + VM_WAIT; VM_OBJECT_LOCK(object); goto retry; } Modified: stable/6/sys/vm/vm_pageout.c ============================================================================== --- stable/6/sys/vm/vm_pageout.c Fri Mar 19 21:29:30 2010 (r205348) +++ stable/6/sys/vm/vm_pageout.c Fri Mar 19 22:39:27 2010 (r205349) @@ -711,9 +711,6 @@ vm_pageout_scan(int pass) struct vm_page marker; int page_shortage, maxscan, pcount; int addl_page_shortage, addl_page_shortage_init; - struct proc *p, *bigproc; - struct thread *td; - vm_offset_t size, bigsize; vm_object_t object; int actcount, cache_cur, cache_first_failure; static int cache_last_free; @@ -1246,7 +1243,23 @@ unlock_and_continue: * doing this on the first pass in order to give ourselves a * chance to flush out dirty vnode-backed pages and to allow * active pages to be moved to the inactive queue and reclaimed. - * + */ + if (pass != 0 && + ((swap_pager_avail < 64 && vm_page_count_min()) || + (swap_pager_full && vm_paging_target() > 0))) + vm_pageout_oom(VM_OOM_MEM); +} + + +void +vm_pageout_oom(int shortage) +{ + struct proc *p, *bigproc; + vm_offset_t size, bigsize; + struct thread *td; + struct vmspace *vm; + + /* * We keep the process bigproc locked once we find it to keep anyone * from messing with it; however, there is a possibility of * deadlock if process B is bigproc and one of it's child processes @@ -1254,77 +1267,81 @@ unlock_and_continue: * lock while walking this list. To avoid this, we don't block on * the process lock but just skip a process if it is already locked. */ - if (pass != 0 && - ((swap_pager_avail < 64 && vm_page_count_min()) || - (swap_pager_full && vm_paging_target() > 0))) { - bigproc = NULL; - bigsize = 0; - sx_slock(&allproc_lock); - FOREACH_PROC_IN_SYSTEM(p) { - int breakout; + bigproc = NULL; + bigsize = 0; + sx_slock(&allproc_lock); + FOREACH_PROC_IN_SYSTEM(p) { + int breakout; - if (PROC_TRYLOCK(p) == 0) - continue; - /* - * If this is a system or protected process, skip it. - */ - if ((p->p_flag & P_SYSTEM) || (p->p_pid == 1) || - (p->p_flag & P_PROTECTED) || - ((p->p_pid < 48) && (swap_pager_avail != 0))) { - PROC_UNLOCK(p); - continue; - } - /* - * If the process is in a non-running type state, - * don't touch it. Check all the threads individually. - */ - mtx_lock_spin(&sched_lock); - breakout = 0; - FOREACH_THREAD_IN_PROC(p, td) { - if (!TD_ON_RUNQ(td) && - !TD_IS_RUNNING(td) && - !TD_IS_SLEEPING(td)) { - breakout = 1; - break; - } - } - if (breakout) { - mtx_unlock_spin(&sched_lock); - PROC_UNLOCK(p); - continue; - } - mtx_unlock_spin(&sched_lock); - /* - * get the process size - */ - if (!vm_map_trylock_read(&p->p_vmspace->vm_map)) { - PROC_UNLOCK(p); - continue; + if (PROC_TRYLOCK(p) == 0) + continue; + /* + * If this is a system or protected process, skip it. + */ + if ((p->p_flag & (P_INEXEC | P_PROTECTED | P_SYSTEM)) || + (p->p_pid == 1) || + ((p->p_pid < 48) && (swap_pager_avail != 0))) { + PROC_UNLOCK(p); + continue; + } + /* + * If the process is in a non-running type state, + * don't touch it. Check all the threads individually. + */ + mtx_lock_spin(&sched_lock); + breakout = 0; + FOREACH_THREAD_IN_PROC(p, td) { + if (!TD_ON_RUNQ(td) && + !TD_IS_RUNNING(td) && + !TD_IS_SLEEPING(td)) { + breakout = 1; + break; } - size = vmspace_swap_count(p->p_vmspace); - vm_map_unlock_read(&p->p_vmspace->vm_map); - size += vmspace_resident_count(p->p_vmspace); - /* - * if the this process is bigger than the biggest one - * remember it. - */ - if (size > bigsize) { - if (bigproc != NULL) - PROC_UNLOCK(bigproc); - bigproc = p; - bigsize = size; - } else - PROC_UNLOCK(p); } - sx_sunlock(&allproc_lock); - if (bigproc != NULL) { - killproc(bigproc, "out of swap space"); - mtx_lock_spin(&sched_lock); - sched_nice(bigproc, PRIO_MIN); + if (breakout) { mtx_unlock_spin(&sched_lock); - PROC_UNLOCK(bigproc); - wakeup(&cnt.v_free_count); + PROC_UNLOCK(p); + continue; + } + mtx_unlock_spin(&sched_lock); + /* + * get the process size + */ + vm = vmspace_acquire_ref(p); + if (vm == NULL) { + PROC_UNLOCK(p); + continue; } + if (!vm_map_trylock_read(&vm->vm_map)) { + vmspace_free(vm); + PROC_UNLOCK(p); + continue; + } + size = vmspace_swap_count(vm); + vm_map_unlock_read(&vm->vm_map); + if (shortage == VM_OOM_MEM) + size += vmspace_resident_count(vm); + vmspace_free(vm); + /* + * if the this process is bigger than the biggest one + * remember it. + */ + if (size > bigsize) { + if (bigproc != NULL) + PROC_UNLOCK(bigproc); + bigproc = p; + bigsize = size; + } else + PROC_UNLOCK(p); + } + sx_sunlock(&allproc_lock); + if (bigproc != NULL) { + killproc(bigproc, "out of swap space"); + mtx_lock_spin(&sched_lock); + sched_nice(bigproc, PRIO_MIN); + mtx_unlock_spin(&sched_lock); + PROC_UNLOCK(bigproc); + wakeup(&cnt.v_free_count); } } @@ -1595,6 +1612,7 @@ vm_daemon() struct rlimit rsslim; struct proc *p; struct thread *td; + struct vmspace *vm; int breakout, swapout_flags; while (TRUE) { @@ -1619,7 +1637,7 @@ vm_daemon() * looked at this process, skip it. */ PROC_LOCK(p); - if (p->p_flag & (P_SYSTEM | P_WEXIT)) { + if (p->p_flag & (P_INEXEC | P_SYSTEM | P_WEXIT)) { PROC_UNLOCK(p); continue; } @@ -1656,13 +1674,17 @@ vm_daemon() */ if ((p->p_sflag & PS_INMEM) == 0) limit = 0; /* XXX */ + vm = vmspace_acquire_ref(p); PROC_UNLOCK(p); + if (vm == NULL) + continue; - size = vmspace_resident_count(p->p_vmspace); + size = vmspace_resident_count(vm); if (limit >= 0 && size >= limit) { vm_pageout_map_deactivate_pages( - &p->p_vmspace->vm_map, limit); + &vm->vm_map, limit); } + vmspace_free(vm); } sx_sunlock(&allproc_lock); } Modified: stable/6/sys/vm/vm_pageout.h ============================================================================== --- stable/6/sys/vm/vm_pageout.h Fri Mar 19 21:29:30 2010 (r205348) +++ stable/6/sys/vm/vm_pageout.h Fri Mar 19 22:39:27 2010 (r205349) @@ -83,6 +83,9 @@ extern int vm_pageout_page_count; #define VM_SWAP_NORMAL 1 #define VM_SWAP_IDLE 2 +#define VM_OOM_MEM 1 +#define VM_OOM_SWAPZ 2 + /* * Exported routines. */ @@ -99,5 +102,6 @@ extern void vm_waitpfault(void); #ifdef _KERNEL int vm_pageout_flush(vm_page_t *, int, int); +void vm_pageout_oom(int shortage); #endif #endif /* _VM_VM_PAGEOUT_H_ */